Skip to content

Commit

Permalink
Allow to configure gitOps during kindless management cluster (#6771)
Browse files Browse the repository at this point in the history
  • Loading branch information
panktishah26 authored Oct 6, 2023
1 parent 131471c commit 2de41c8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/api/v1alpha1/cluster_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ func validateImmutableFieldsCluster(new, old *Cluster) field.ErrorList {
}
}

if !new.Spec.GitOpsRef.Equal(old.Spec.GitOpsRef) {
if !new.Spec.GitOpsRef.Equal(old.Spec.GitOpsRef) && !old.IsSelfManaged() {
allErrs = append(
allErrs,
field.Forbidden(specPath.Child("GitOpsRef"), fmt.Sprintf("field is immutable %v", new.Spec.GitOpsRef)))
Expand Down
15 changes: 15 additions & 0 deletions pkg/api/v1alpha1/cluster_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -692,8 +692,19 @@ func TestClusterValidateUpdateGitOpsRefImmutableNilEqual(t *testing.T) {
g.Expect(c.ValidateUpdate(cOld)).To(Succeed())
}

func TestClusterValidateUpdateGitOpsRefMutableManagementCluster(t *testing.T) {
cOld := baseCluster()
cOld.Spec.GitOpsRef = nil
c := cOld.DeepCopy()
c.Spec.GitOpsRef = &v1alpha1.Ref{Name: "test2", Kind: "GitOpsConfig"}

g := NewWithT(t)
g.Expect(c.ValidateUpdate(cOld)).To(Succeed())
}

func TestClusterValidateUpdateGitOpsRefImmutable(t *testing.T) {
cOld := baseCluster()
cOld.SetManagedBy("management-cluster")
cOld.Spec.GitOpsRef = &v1alpha1.Ref{}
c := cOld.DeepCopy()
c.Spec.GitOpsRef = &v1alpha1.Ref{Name: "test2", Kind: "GitOpsConfig2"}
Expand All @@ -704,6 +715,7 @@ func TestClusterValidateUpdateGitOpsRefImmutable(t *testing.T) {

func TestClusterValidateUpdateGitOpsRefImmutableName(t *testing.T) {
cOld := baseCluster()
cOld.SetManagedBy("management-cluster")
cOld.Spec.GitOpsRef = &v1alpha1.Ref{
Name: "test1", Kind: "GitOpsConfig",
}
Expand All @@ -716,6 +728,7 @@ func TestClusterValidateUpdateGitOpsRefImmutableName(t *testing.T) {

func TestClusterValidateUpdateGitOpsRefImmutableKind(t *testing.T) {
cOld := baseCluster()
cOld.SetManagedBy("management-cluster")
cOld.Spec.GitOpsRef = &v1alpha1.Ref{
Name: "test", Kind: "GitOpsConfig1",
}
Expand All @@ -728,6 +741,7 @@ func TestClusterValidateUpdateGitOpsRefImmutableKind(t *testing.T) {

func TestClusterValidateUpdateGitOpsRefOldNilImmutable(t *testing.T) {
cOld := baseCluster()
cOld.SetManagedBy("management-cluster")
cOld.Spec.GitOpsRef = nil

c := cOld.DeepCopy()
Expand All @@ -739,6 +753,7 @@ func TestClusterValidateUpdateGitOpsRefOldNilImmutable(t *testing.T) {

func TestClusterValidateUpdateGitOpsRefNewNilImmutable(t *testing.T) {
cOld := baseCluster()
cOld.SetManagedBy("management-cluster")
cOld.Spec.GitOpsRef = &v1alpha1.Ref{
Name: "test", Kind: "GitOpsConfig",
}
Expand Down

0 comments on commit 2de41c8

Please sign in to comment.