MCPcopy Create free account
hub / github.com/devfile/devworkspace-operator / PullSecrets

Function PullSecrets

pkg/provision/workspace/pull_secret.go:43–90  ·  view source on GitHub ↗
(clusterAPI sync.ClusterAPI, serviceAccountName, namespace string)

Source from the content-addressed store, hash-verified

41)
42
43func PullSecrets(clusterAPI sync.ClusterAPI, serviceAccountName, namespace string) (*v1alpha1.PodAdditions, error) {
44 labelSelector, err := labels.Parse(fmt.Sprintf("%s=%s", constants.DevWorkspacePullSecretLabel, "true"))
45 if err != nil {
46 return nil, &dwerrors.FailError{Message: "Failed to get pull secrets", Err: err}
47 }
48
49 secrets := corev1.SecretList{}
50 err = clusterAPI.Client.List(context.TODO(), &secrets, &client.ListOptions{
51 Namespace: namespace,
52 LabelSelector: labelSelector,
53 })
54 if err != nil {
55 return nil, err
56 }
57
58 serviceAccount := &corev1.ServiceAccount{}
59 namespacedName := types.NamespacedName{
60 Name: serviceAccountName,
61 Namespace: namespace,
62 }
63 err = clusterAPI.Client.Get(context.TODO(), namespacedName, serviceAccount)
64 if err != nil {
65 if k8sErrors.IsNotFound(err) {
66 // ServiceAccount does not exist, no pull secrets to extract
67 return &v1alpha1.PodAdditions{}, nil
68 }
69 return nil, err
70 }
71
72 if infrastructure.IsOpenShift() {
73 if len(serviceAccount.ImagePullSecrets) == 0 && serviceAccount.CreationTimestamp.Add(pullSecretCreationTimeout).After(time.Now()) {
74 return nil, &dwerrors.RetryError{Message: "Waiting for image pull secrets"}
75 }
76 }
77
78 dockerCfgs := serviceAccount.ImagePullSecrets
79 for _, s := range secrets.Items {
80 if s.Type == corev1.SecretTypeDockercfg || s.Type == corev1.SecretTypeDockerConfigJson {
81 dockerCfgs = append(dockerCfgs, corev1.LocalObjectReference{Name: s.Name})
82 }
83 }
84
85 sort.Slice(dockerCfgs, func(i, j int) bool {
86 return strings.Compare(dockerCfgs[i].Name, dockerCfgs[j].Name) < 0
87 })
88
89 return &v1alpha1.PodAdditions{PullSecrets: dockerCfgs}, nil
90}

Callers 1

Calls 2

IsOpenShiftFunction · 0.92
GetMethod · 0.65

Tested by 1