-
Notifications
You must be signed in to change notification settings - Fork 30
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
feat: Add mandatory-module label to mandatory ModuleTemplate #2033
base: main
Are you sure you want to change the base?
Changes from all commits
5117c7b
6d6fe1c
0e41df0
44ae9f7
d317af4
fa8b57e
6d89545
fc75660
23f10cc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,9 @@ func NewModuleTemplateBuilder() ModuleTemplateBuilder { | |
ObjectMeta: apimetav1.ObjectMeta{ | ||
Name: random.Name(), | ||
Namespace: apimetav1.NamespaceDefault, | ||
Labels: map[string]string{ | ||
shared.IsMandatoryModule: shared.EnableLabelValue, | ||
}, | ||
Comment on lines
+37
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am a bit confused by this change. Isn't this applying the mandatory module label to all tests? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes but that's for the integration tests in which some don't have the kyma controller initialized. also, there is another followup issue to this to introduce the label using modulectl create command, so anyways the label should be there before the kyma controller |
||
}, | ||
Spec: v1beta2.ModuleTemplateSpec{ | ||
Data: data, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import ( | |
|
||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
"github.com/kyma-project/lifecycle-manager/api/shared" | ||
"github.com/kyma-project/lifecycle-manager/api/v1beta2" | ||
"github.com/kyma-project/lifecycle-manager/internal/descriptor/provider" | ||
"github.com/kyma-project/lifecycle-manager/pkg/templatelookup" | ||
|
@@ -79,6 +80,31 @@ func UpdateModuleTemplateSpec(ctx context.Context, | |
return nil | ||
} | ||
|
||
func MandatoryModuleTemplateHasExpectedLabel(ctx context.Context, clnt client.Client, moduleName, key, value string, | ||
) error { | ||
mandatoryModuleTemplates, err := templatelookup.GetMandatory(ctx, clnt) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var moduleTemplate *v1beta2.ModuleTemplate | ||
for _, moduleTemplateInfo := range mandatoryModuleTemplates { | ||
if moduleTemplateInfo.ModuleTemplate.Labels[shared.ModuleName] == moduleName { | ||
moduleTemplate = moduleTemplateInfo.ModuleTemplate | ||
break | ||
} | ||
} | ||
|
||
if moduleTemplate == nil { | ||
return fmt.Errorf("module template not found, %s", moduleName) | ||
} | ||
|
||
if moduleTemplate.Labels[key] != value { | ||
return fmt.Errorf("label %s:%s not found", key, value) | ||
} | ||
return nil | ||
} | ||
|
||
Comment on lines
+83
to
+107
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am okay with this as is, but one idea to simplify may be to use the lookup by label already. I.e., get all ModuleTemplates with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the GetMandatory already uses the label for the lookup |
||
func DeleteModuleTemplate(ctx context.Context, | ||
clnt client.Client, module v1beta2.Module, kymaChannel string, namespace string, | ||
) error { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could also add a field selector
client.MatchingFields{"metadata.deletionTimestamp": ""}
. Then we could get rid of filtering in the for loop bellow.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason I am unable to use this, because if I use the fieldselector I will have to provide the field name and value