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: support set labels for env #4422

Merged
merged 2 commits into from
Jul 29, 2022
Merged

Conversation

huanghantao
Copy link
Contributor

@huanghantao huanghantao commented Jul 21, 2022

Signed-off-by: codinghuang codinghuang@qq.com

Description of your changes

Fixes #4180

I have:

  • Read and followed KubeVela's contribution process.
  • Related Docs updated properly. In a new feature or configuration option, an update to the documentation is necessary.
  • Run make reviewable to ensure this PR is ready for review.
  • Added backport release-x.y labels to auto-backport this PR if necessary.

How has this code been tested

Manually tested with possible user inputs. Unit tests for the util function are added.

Special notes for your reviewer

change --label to --labels, so we can set multiple labels:

vela env set prod --labels="key1=value1,key2=value2"

@codecov
Copy link

codecov bot commented Jul 21, 2022

Codecov Report

Merging #4422 (abf756f) into master (d386b64) will increase coverage by 10.20%.
The diff coverage is 0.00%.

@@             Coverage Diff             @@
##           master    #4422       +/-   ##
===========================================
+ Coverage   51.27%   61.48%   +10.20%     
===========================================
  Files         325      347       +22     
  Lines       33400    34278      +878     
===========================================
+ Hits        17126    21075     +3949     
+ Misses      13981    10453     -3528     
- Partials     2293     2750      +457     
Flag Coverage Δ
apiserver-e2etests 27.27% <ø> (?)
apiserver-unittests 40.10% <ø> (+0.02%) ⬆️
core-unittests 56.45% <0.00%> (+0.01%) ⬆️
e2e-multicluster-test 19.83% <0.00%> (?)
e2e-rollout-tests 22.26% <ø> (-0.06%) ⬇️
e2etests 28.67% <ø> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pkg/utils/env/env.go 9.21% <0.00%> (-1.35%) ⬇️
apis/core.oam.dev/v1beta1/policy_definition.go 0.00% <0.00%> (-50.00%) ⬇️
...aits/traitdefinition/traitdefinition_controller.go 65.26% <0.00%> (-5.27%) ⬇️
pkg/controller/utils/capability.go 79.82% <0.00%> (-0.45%) ⬇️
...es/policydefinition/policydefinition_controller.go 64.21% <0.00%> (ø)
pkg/cloudprovider/cluster.go 0.00% <0.00%> (ø)
pkg/apiserver/domain/model/envbinding.go 100.00% <0.00%> (ø)
...kg/apiserver/interfaces/api/assembler/v1/do2dto.go 83.68% <0.00%> (ø)
pkg/cmd/completion.go 0.00% <0.00%> (ø)
pkg/cmd/factory.go 78.78% <0.00%> (ø)
... and 144 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d386b64...abf756f. Read the comment docs.

Signed-off-by: codinghuang <codinghuang@qq.com>
return nil, fmt.Errorf("the label string can't be empty")
}
labels := map[string]string{}
labelStrings := strings.Split(labelString, ",")
Copy link
Member

@charlie0129 charlie0129 Jul 21, 2022

Choose a reason for hiding this comment

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

Great, but if you are to write the label parser, remember to remove spaces inside the string first to prevent subtle problems.

Example in k8s.io/cli-runtime:
https://github.com/kubernetes/cli-runtime/blob/4661c56a3b88e2288cba9b858718fca45f522e02/pkg/resource/builder.go#L480-L481

But I would suggest that you take a look at k8s.io/apimachinery/pkg/labels for some existing parsers, instead of writing your own:
https://github.com/kubernetes/apimachinery/blob/cff14a57b273bd82d64efc85aa0835aaf847a3ef/pkg/labels/labels.go#L146-L148

use k8s.io/apimachinery/pkg/labels

Signed-off-by: codinghuang <codinghuang@qq.com>
Copy link
Collaborator

@wonderflow wonderflow left a comment

Choose a reason for hiding this comment

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

great work

references/cli/env.go Show resolved Hide resolved
apis/types/types.go Show resolved Hide resolved
@@ -131,6 +131,7 @@ func NewEnvDeleteCommand(c common.Args, ioStreams cmdutil.IOStreams) *cobra.Comm

// NewEnvSetCommand creates `env set` command for setting current environment
func NewEnvSetCommand(c common.Args, ioStreams cmdutil.IOStreams) *cobra.Command {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this Feature only for vela CLI? Does api-server need update api?

@Somefive Somefive added the backport release-1.5 add this label will automatically backport this PR to release-1.5 branch label Jul 29, 2022
@Somefive Somefive merged commit f1790e5 into kubevela:master Jul 29, 2022
@github-actions
Copy link

Successfully created backport PR #4506 for release-1.5.

@huanghantao huanghantao deleted the set-env-labels branch March 7, 2023 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport release-1.5 add this label will automatically backport this PR to release-1.5 branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

support vela env set --labels for K8s namespace
5 participants