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
+10 -15
View File
@@ -17,22 +17,17 @@ limitations under the License.
package util
import (
"github.com/pkg/errors"
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.
func ApplyImagePullSecret(client *kubernetes.Clientset, secret string, secretNS string, podspec apiv1.PodSpec) (*apiv1.PodSpec, error) {
if len(secret) > 0 && client != nil {
_, err := client.CoreV1().Secrets(secretNS).Get(secret, metav1.GetOptions{})
if err != nil {
err = errors.Wrapf(err, "unable to get image pull secret '%v' under namespace '%v'",
secret, secretNS)
return nil, err
}
podspec.ImagePullSecrets = []apiv1.LocalObjectReference{{Name: secret}}
}
return &podspec, nil
// ApplyImagePullSecret applies image pull secret to the give pod spec.
// It's intentional not to check the existence of secret here.
// First, Kubernetes will set Pod status to "ImagePullBackOff" once
// kubelet failed to pull image so that users will know what's happening.
// Second, Fission no longer need to handle "secret not found" error
// when creating the environment deployment since kubelet will retry to
// pull image until successes.
func ApplyImagePullSecret(secret string, podspec apiv1.PodSpec) *apiv1.PodSpec {
podspec.ImagePullSecrets = []apiv1.LocalObjectReference{{Name: secret}}
return &podspec
}