Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to configure gitOps during kindless management cluster #6771

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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