Skip to content

Commit

Permalink
fix IsUnmanaged detection
Browse files Browse the repository at this point in the history
  • Loading branch information
ruanxin committed Sep 6, 2024
1 parent 1e0a685 commit 9e511ba
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
2 changes: 1 addition & 1 deletion api/v1beta2/manifest_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (manifest *Manifest) SetStatus(status shared.Status) {
}

func (manifest *Manifest) IsUnmanaged() bool {
return manifest.GetAnnotations() != nil && manifest.GetAnnotations()[shared.UnmanagedAnnotation] != ""
return manifest.GetAnnotations() != nil && manifest.GetAnnotations()[shared.UnmanagedAnnotation] == shared.EnableLabelValue
}

func (manifest *Manifest) IsMandatoryModule() bool {
Expand Down
37 changes: 34 additions & 3 deletions pkg/module/sync/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func configureModuleInKyma(
func TestNeedToUpdate(t *testing.T) {
type args struct {
manifestInCluster *v1beta2.Manifest
manifestObj *v1beta2.Manifest
newManifest *v1beta2.Manifest
moduleStatus *v1beta2.ModuleStatus
module *common.Module
}
Expand Down Expand Up @@ -355,6 +355,37 @@ func TestNeedToUpdate(t *testing.T) {
},
false,
},
{
"When cluster Manifest is managed and module is unmanaged, expect update",
args{
&v1beta2.Manifest{
ObjectMeta: apimetav1.ObjectMeta{
Annotations: map[string]string{shared.UnmanagedAnnotation: "false"},
},
Status: shared.Status{
State: "Ready",
},
},
&v1beta2.Manifest{},
&v1beta2.ModuleStatus{
State: "Ready", Template: &v1beta2.TrackingObject{
PartialMeta: v1beta2.PartialMeta{
Generation: trackedModuleTemplateGeneration,
},
},
}, &common.Module{
Template: &templatelookup.ModuleTemplateInfo{
ModuleTemplate: &v1beta2.ModuleTemplate{
ObjectMeta: apimetav1.ObjectMeta{
Generation: trackedModuleTemplateGeneration,
},
},
},
IsUnmanaged: true,
},
},
true,
},
{
"When no update required, expect no update",
args{
Expand Down Expand Up @@ -430,9 +461,9 @@ func TestNeedToUpdate(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, sync.NeedToUpdate(tt.args.manifestInCluster, tt.args.manifestObj,
assert.Equalf(t, tt.want, sync.NeedToUpdate(tt.args.manifestInCluster, tt.args.newManifest,
tt.args.moduleStatus, tt.args.module), "needToUpdate(%v, %v, %v)",
tt.args.manifestInCluster, tt.args.manifestObj,
tt.args.manifestInCluster, tt.args.newManifest,
tt.args.moduleStatus)
})
}
Expand Down

0 comments on commit 9e511ba

Please sign in to comment.