Skip to content

Commit

Permalink
svc for internal git server
Browse files Browse the repository at this point in the history
Signed-off-by: Austin Abro <[email protected]>
  • Loading branch information
AustinAbro321 committed Aug 20, 2024
1 parent ade03ab commit a19fb62
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
2 changes: 0 additions & 2 deletions src/cmd/tools/zarf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
9 changes: 9 additions & 0 deletions src/pkg/cluster/zarf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
38 changes: 38 additions & 0 deletions src/pkg/cluster/zarf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
}

0 comments on commit a19fb62

Please sign in to comment.