Skip to content

Commit 347171c

Browse files
authored
Allow multiple pullsecrets during image auth (#843)
* Allow multi pullsecrets during image auth * Address PR comments * Add pull secret name to error log
1 parent 48a19a1 commit 347171c

1 file changed

Lines changed: 21 additions & 9 deletions

File tree

internal/controller/webspherelibertyapplication_controller.go

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,17 +1160,29 @@ func (r *ReconcileWebSphereLiberty) getContainerImageMetadata(reqLogger logr.Log
11601160
wlappSecrets := []corev1.Secret{}
11611161
var pullSecret *corev1.Secret
11621162
if wlapp.GetPullSecret() != nil {
1163-
pullSecret = &corev1.Secret{}
1164-
if err := r.GetClient().Get(context.TODO(), types.NamespacedName{Name: *wlapp.GetPullSecret(), Namespace: wlapp.GetNamespace()}, pullSecret); err != nil {
1165-
if kerrors.IsNotFound(err) {
1166-
reqLogger.Info("The instance pull secret specified does not exist")
1167-
pullSecret = nil
1168-
} else {
1169-
reqLogger.Error(err, "Failed to get the instance pull secret")
1170-
return "", nil, fmt.Errorf("Failed to get the instance pull secret: %v", err)
1163+
pullSecretString := strings.TrimSpace(*wlapp.GetPullSecret())
1164+
pullSecretNames := []string{}
1165+
if strings.Contains(pullSecretString, ",") {
1166+
pullSecretNames = strings.Split(pullSecretString, ",")
1167+
} else {
1168+
pullSecretNames = append(pullSecretNames, pullSecretString)
1169+
}
1170+
for _, pullSecretName := range pullSecretNames {
1171+
pullSecretName = strings.TrimSpace(pullSecretName)
1172+
pullSecret = &corev1.Secret{}
1173+
if err := r.GetClient().Get(context.TODO(), types.NamespacedName{Name: pullSecretName, Namespace: wlapp.GetNamespace()}, pullSecret); err != nil {
1174+
if kerrors.IsNotFound(err) {
1175+
reqLogger.Info(fmt.Sprintf("The instance pull secret %s does not exist", pullSecretName))
1176+
pullSecret = nil
1177+
} else {
1178+
reqLogger.Error(err, fmt.Sprintf("Failed to get the instance pull secret %s", pullSecretName))
1179+
return "", nil, fmt.Errorf("Failed to get the instance pull secret %s: %v", pullSecretName, err)
1180+
}
1181+
}
1182+
if pullSecret != nil {
1183+
wlappSecrets = append(wlappSecrets, *pullSecret)
11711184
}
11721185
}
1173-
wlappSecrets = append(wlappSecrets, *pullSecret)
11741186
}
11751187
return libertyimage.NewNamespaceCredentialsContext(reqLogger, wlappSecrets, wlapp.GetNamespace()).GetContainerImageMetadata(context.TODO(), imageRef, pullSecret, false)
11761188
}

0 commit comments

Comments
 (0)