diff --git a/src/cmd/tools/zarf.go b/src/cmd/tools/zarf.go index c095d82a7a..f84c80de40 100644 --- a/src/cmd/tools/zarf.go +++ b/src/cmd/tools/zarf.go @@ -188,8 +188,6 @@ var updateCredsCmd = &cobra.Command{ if slices.Contains(args, message.GitKey) && newState.GitServer.IsInternal() { err := c.UpdateInternalGitServerSecret(cmd.Context(), oldState.GitServer, newState.GitServer) updateErr := fmt.Errorf("unable to update Zarf Git Server values: %w", err) - // TODO once Zarf is changed so the default state is empty for a service when it is not deployed - // and sufficient time has passed for users state to get updated we should error on isNotFound if err != nil && !kerrors.IsNotFound(err) { return updateErr } diff --git a/src/pkg/cluster/zarf.go b/src/pkg/cluster/zarf.go index d2a50b4983..14c3e2f31a 100644 --- a/src/pkg/cluster/zarf.go +++ b/src/pkg/cluster/zarf.go @@ -349,3 +349,12 @@ func (c *Cluster) UpdateInternalGitServerSecret(ctx context.Context, oldGitServe } return nil } + +// InternalGitServerExists checks if the Zarf internal git server exists in the cluster. +func (c *Cluster) InternalGitServerExists(ctx context.Context) (bool, error) { + _, err := c.Clientset.CoreV1().Services(ZarfNamespaceName).Get(ctx, ZarfGitServerName, metav1.GetOptions{}) + if err != nil && !kerrors.IsNotFound(err) { + return false, err + } + return !kerrors.IsNotFound(err), nil +} diff --git a/src/pkg/cluster/zarf_test.go b/src/pkg/cluster/zarf_test.go index fe8b91d188..d2f3aefcde 100644 --- a/src/pkg/cluster/zarf_test.go +++ b/src/pkg/cluster/zarf_test.go @@ -285,3 +285,41 @@ func TestRegistryHPA(t *testing.T) { require.NoError(t, err) require.Equal(t, autoscalingv2.DisabledPolicySelect, *disableHpa.Spec.Behavior.ScaleDown.SelectPolicy) } + +func TestInternalGitServerExists(t *testing.T) { + tests := []struct { + name string + svc *corev1.Service + expectedExist bool + expectedErr error + }{ + { + name: "Git server exists", + svc: &corev1.Service{ObjectMeta: metav1.ObjectMeta{Name: ZarfGitServerName, Namespace: ZarfNamespaceName}}, + expectedExist: true, + expectedErr: nil, + }, + { + name: "Git server does not exist", + svc: nil, + expectedExist: false, + expectedErr: nil, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + cs := fake.NewSimpleClientset() + cluster := &Cluster{Clientset: cs} + ctx := context.Background() + if tt.svc != nil { + _, err := cs.CoreV1().Services(tt.svc.Namespace).Create(ctx, tt.svc, metav1.CreateOptions{}) + require.NoError(t, err) + } + + exists, err := cluster.InternalGitServerExists(ctx) + require.Equal(t, tt.expectedExist, exists) + require.Equal(t, tt.expectedErr, err) + }) + } +}