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

add enable-feature command #44

Merged
merged 3 commits into from
Jul 2, 2024

Conversation

MatousJobanek
Copy link
Contributor

@MatousJobanek MatousJobanek commented Jun 28, 2024

SANDBOX-661

a command to enable a feature for the given space

EDIT: pushed another commit that checks if the requested feature is in the list of the supported toggle features in ToolchainConfig.

Copy link

codecov bot commented Jun 28, 2024

Codecov Report

Attention: Patch coverage is 81.03448% with 11 lines in your changes missing coverage. Please review.

Project coverage is 66.79%. Comparing base (ffc4214) to head (b33810a).

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #44      +/-   ##
==========================================
+ Coverage   66.43%   66.79%   +0.36%     
==========================================
  Files          41       42       +1     
  Lines        2276     2334      +58     
==========================================
+ Hits         1512     1559      +47     
- Misses        584      591       +7     
- Partials      180      184       +4     
Files Coverage Δ
pkg/cmd/root.go 88.57% <100.00%> (+0.33%) ⬆️
pkg/cmd/enable-feature.go 80.70% <80.70%> (ø)

@MatousJobanek MatousJobanek changed the title add enabled-feature command add enable-feature command Jun 28, 2024
Copy link
Contributor

@mfrancisc mfrancisc left a comment

Choose a reason for hiding this comment

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

Looks great 🥇

I have only few minor comments.

I was wondering if we want to support list of features and/or list of spaces, but I believe running the command multiple times is more then fine, considering that execution time is very short.

pkg/cmd/enable-feature.go Show resolved Hide resolved
Comment on lines +56 to +60
if data.alreadyEnabled != "" {
space.Annotations = map[string]string{
toolchainv1alpha1.FeatureToggleNameAnnotationKey: data.alreadyEnabled,
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can always update the annotations, the result shouldn't change

Suggested change
if data.alreadyEnabled != "" {
space.Annotations = map[string]string{
toolchainv1alpha1.FeatureToggleNameAnnotationKey: data.alreadyEnabled,
}
}
space.Annotations = map[string]string{
toolchainv1alpha1.FeatureToggleNameAnnotationKey: data.alreadyEnabled,
}

Copy link
Contributor

Choose a reason for hiding this comment

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

I would keep it as is. Just to make sure we do not touch the annotation map at all if the initial feature list is not set. There is still a difference between an empty map and nil.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, as Alexey mentioned, it's not the same. We need to make sure that the logic will work when annotations are no initialized (the map is nil). If we don't handle such a case properly, then we could end up with panic trying to modify a map that is 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 see, but applying my suggestion the tests are still passing, so I'm wondering if we are missing some specific case that sets the annotation to nil to cover this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's the other way around. Your version puts lower requirements on the code than the current test.
Imagine that we don't have these 3 lines of the code

if space.Annotations == nil {
space.Annotations = map[string]string{}
}

Your version of the tests will pass, but the current version will fail

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok I see now, as you explained in our 1:1 this check makes so that we test the nil scenario by not setting any annotation in the setup part of the test and leaving it as nil in the first iterartion. Thanks for explaining and sorry fo the confusion.

Comment on lines +110 to +114
if alreadyEnabled != "" {
space.Annotations = map[string]string{
toolchainv1alpha1.FeatureToggleNameAnnotationKey: alreadyEnabled,
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

same here, we could always update the annotations I believe

Suggested change
if alreadyEnabled != "" {
space.Annotations = map[string]string{
toolchainv1alpha1.FeatureToggleNameAnnotationKey: alreadyEnabled,
}
}
space.Annotations = map[string]string{
toolchainv1alpha1.FeatureToggleNameAnnotationKey: alreadyEnabled,
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The same - we need to verify the case when there is no annotation provided at all (the map is nil).

Copy link
Contributor

Choose a reason for hiding this comment

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

same here, when I try this change the tests are still passing

Copy link
Contributor

@alexeykazakov alexeykazakov left a comment

Choose a reason for hiding this comment

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

Nice!
Now we need a command for disabling a feature :) I didn't notice that it's already there: #45 Nice!

Copy link
Contributor

@mfrancisc mfrancisc left a comment

Choose a reason for hiding this comment

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

Looks great 👍

@MatousJobanek MatousJobanek merged commit 9d398a8 into kubesaw:master Jul 2, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants