(ctx context.Context, c client.Client, workspace *dw.DevWorkspace, dwOperatorConfig *controllerv1alpha1.OperatorConfiguration, operatorConfigNamespace string, scheme *runtime.Scheme, log logr.Logger, )
| 40 | } |
| 41 | |
| 42 | func HandleRegistryAuthSecret(ctx context.Context, c client.Client, workspace *dw.DevWorkspace, |
| 43 | dwOperatorConfig *controllerv1alpha1.OperatorConfiguration, operatorConfigNamespace string, scheme *runtime.Scheme, log logr.Logger, |
| 44 | ) (*corev1.Secret, error) { |
| 45 | if dwOperatorConfig.Workspace == nil || |
| 46 | dwOperatorConfig.Workspace.BackupCronJob == nil || |
| 47 | dwOperatorConfig.Workspace.BackupCronJob.Registry == nil { |
| 48 | return nil, fmt.Errorf("backup/restore configuration not properly set in DevWorkspaceOperatorConfig") |
| 49 | } |
| 50 | |
| 51 | registryAuthSecret := &corev1.Secret{} |
| 52 | err := c.Get(ctx, client.ObjectKey{ |
| 53 | Name: constants.DevWorkspaceBackupAuthSecretName, |
| 54 | Namespace: workspace.Namespace}, registryAuthSecret) |
| 55 | if err == nil { |
| 56 | log.Info("Successfully retrieved registry auth secret for backup from workspace namespace", |
| 57 | "secretName", constants.DevWorkspaceBackupAuthSecretName) |
| 58 | return registryAuthSecret, nil |
| 59 | } |
| 60 | if client.IgnoreNotFound(err) != nil { |
| 61 | return nil, err |
| 62 | } |
| 63 | // Check if AuthSecret is configured in operator config |
| 64 | authSecretName := dwOperatorConfig.Workspace.BackupCronJob.Registry.AuthSecret |
| 65 | if len(authSecretName) == 0 { |
| 66 | log.Info("Registry auth secret not found in workspace namespace and not configured in operator config. "+ |
| 67 | "Proceeding without authentication. Ensure your registry allows anonymous access or configure authentication if needed.", |
| 68 | "secretName", constants.DevWorkspaceBackupAuthSecretName, |
| 69 | "namespace", workspace.Namespace, |
| 70 | "registry", dwOperatorConfig.Workspace.BackupCronJob.Registry.Path) |
| 71 | return nil, nil |
| 72 | } |
| 73 | |
| 74 | if operatorConfigNamespace == "" { |
| 75 | resolvedNS, nsErr := infrastructure.GetNamespace() |
| 76 | if nsErr != nil { |
| 77 | return nil, fmt.Errorf("cannot resolve operator namespace to copy registry auth secret: %w", nsErr) |
| 78 | } |
| 79 | operatorConfigNamespace = resolvedNS |
| 80 | } |
| 81 | |
| 82 | log.Info("Registry auth secret not found in workspace namespace, checking operator namespace", |
| 83 | "secretName", authSecretName, |
| 84 | "operatorNamespace", operatorConfigNamespace) |
| 85 | |
| 86 | // Look for the configured secret name in operator namespace |
| 87 | err = c.Get(ctx, client.ObjectKey{ |
| 88 | Name: authSecretName, |
| 89 | Namespace: operatorConfigNamespace}, registryAuthSecret) |
| 90 | if err != nil { |
| 91 | log.Error(err, "Failed to get registry auth secret for backup job", |
| 92 | "secretName", authSecretName, |
| 93 | "namespace", operatorConfigNamespace) |
| 94 | return nil, err |
| 95 | } |
| 96 | log.Info("Successfully retrieved registry auth secret from operator namespace", |
| 97 | "secretName", authSecretName) |
| 98 | return CopySecret(ctx, c, workspace, registryAuthSecret, scheme, log) |
| 99 | } |
no test coverage detected