Ability to pull builder image from private registry (#1431)

This commit is contained in:
Ta-Ching Chen
2019-11-24 05:17:56 +08:00
committed by GitHub
parent 5c2f0c5f4a
commit 1a5537f4ba
4 changed files with 13 additions and 27 deletions
+1 -2
View File
@@ -495,7 +495,6 @@ func (envw *environmentWatcher) createBuilderDeployment(env *fv1.Environment, ns
} }
finalPodSpec, err := util.MergePodSpec(&podSpec, env.Spec.Builder.PodSpec) finalPodSpec, err := util.MergePodSpec(&podSpec, env.Spec.Builder.PodSpec)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -516,7 +515,7 @@ func (envw *environmentWatcher) createBuilderDeployment(env *fv1.Environment, ns
Labels: sel, Labels: sel,
Annotations: podAnnotations, Annotations: podAnnotations,
}, },
Spec: *finalPodSpec, Spec: *(util.ApplyImagePullSecret(env.Spec.ImagePullSecret, *finalPodSpec)),
}, },
}, },
} }
+1 -5
View File
@@ -239,11 +239,7 @@ func (deploy *NewDeploy) getDeploymentSpec(fn *fv1.Function, env *fv1.Environmen
}, },
} }
podspec, err := util.ApplyImagePullSecret(deploy.kubernetesClient, env.Spec.ImagePullSecret, deployNamespace, pod.Spec) pod.Spec = *(util.ApplyImagePullSecret(env.Spec.ImagePullSecret, pod.Spec))
if err != nil {
return nil, errors.Wrapf(err, "failed to apply image pull secret for env '%v'", env.Metadata.Name)
}
pod.Spec = *podspec
deployment := &appsv1.Deployment{ deployment := &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
+1 -5
View File
@@ -404,11 +404,7 @@ func (gp *GenericPool) createPool() error {
}, },
} }
podspec, err := util.ApplyImagePullSecret(gp.kubernetesClient, gp.env.Spec.ImagePullSecret, gp.namespace, pod.Spec) pod.Spec = *(util.ApplyImagePullSecret(gp.env.Spec.ImagePullSecret, pod.Spec))
if err != nil {
return errors.Wrapf(err, "failed to apply image pull secret for env '%v'", gp.env.Metadata.Name)
}
pod.Spec = *podspec
deployment := &appsv1.Deployment{ deployment := &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
+10 -15
View File
@@ -17,22 +17,17 @@ limitations under the License.
package util package util
import ( import (
"github.com/pkg/errors"
apiv1 "k8s.io/api/core/v1" apiv1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
) )
// ApplyImagePullSecret applies image pull secret to the give pod spec. An error will be returned if failed to get secret. // ApplyImagePullSecret applies image pull secret to the give pod spec.
func ApplyImagePullSecret(client *kubernetes.Clientset, secret string, secretNS string, podspec apiv1.PodSpec) (*apiv1.PodSpec, error) { // It's intentional not to check the existence of secret here.
if len(secret) > 0 && client != nil { // First, Kubernetes will set Pod status to "ImagePullBackOff" once
_, err := client.CoreV1().Secrets(secretNS).Get(secret, metav1.GetOptions{}) // kubelet failed to pull image so that users will know what's happening.
if err != nil { // Second, Fission no longer need to handle "secret not found" error
err = errors.Wrapf(err, "unable to get image pull secret '%v' under namespace '%v'", // when creating the environment deployment since kubelet will retry to
secret, secretNS) // pull image until successes.
return nil, err func ApplyImagePullSecret(secret string, podspec apiv1.PodSpec) *apiv1.PodSpec {
} podspec.ImagePullSecrets = []apiv1.LocalObjectReference{{Name: secret}}
podspec.ImagePullSecrets = []apiv1.LocalObjectReference{{Name: secret}} return &podspec
}
return &podspec, nil
} }