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

feat: Add mandatory-module label to mandatory ModuleTemplate #2033

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

nesmabadr
Copy link
Contributor

Description

Changes proposed in this pull request:

  • Add mandatory-module label to mandatory ModuleTemplate
  • Add tests

Related issue(s)
Resolves #1198

@nesmabadr nesmabadr added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 18, 2024
@nesmabadr nesmabadr requested a review from a team as a code owner November 18, 2024 09:10
@kyma-bot kyma-bot added cla: yes Indicates the PR's author has signed the CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Nov 18, 2024
@kyma-bot kyma-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 18, 2024
@nesmabadr
Copy link
Contributor Author

/cla

@kyma-bot
Copy link
Contributor

Successfully reached out to cla-assistant.io to initialize recheck of PR #2033

Copy link
Contributor

@c-pius c-pius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I missed the discussion while I was on vacation, but I am honestly not sure what we gain from this. The lookup for mandatory modules is maybe slightly simpler as we filter directly by label, but we still need the for loop to map the list to a map. So not much of a simplification or performance gain.
But this comes at the price of rather complex handling in the kyma controller to ensure this label. Maybe I missing the obvious reason why we want to use introduce this label?

Comment on lines +83 to +107
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
}

Copy link
Contributor

Choose a reason for hiding this comment

The 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 operator.kyma-project.io/mandatory-module: true, assert that the len of returned ModuleTemplates is 1 and the entry has the expected module name.

Comment on lines +37 to +39
Labels: map[string]string{
shared.IsMandatoryModule: shared.EnableLabelValue,
},
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Comment on lines +18 to +22
mandatoryModuleTemplateList := &v1beta2.ModuleTemplateList{}
labelSelector := k8slabels.SelectorFromSet(k8slabels.Set{shared.IsMandatoryModule: shared.EnableLabelValue})
if err := kymaClient.List(ctx, mandatoryModuleTemplateList,
&client.ListOptions{LabelSelector: labelSelector}); err != nil {
return nil, fmt.Errorf("could not list mandatory ModuleTemplates: %w", err)
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Indicates the PR's author has signed the CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Mandatory Modules] Introduce mandatory module Label in kyma reconciler
3 participants