Skip to content

Commit

Permalink
add new command
Browse files Browse the repository at this point in the history
Signed-off-by: zhzhuang-zju <m17799853869@163.com>
  • Loading branch information
zhzhuang-zju committed Aug 29, 2024
1 parent c9e0ad7 commit 414362a
Show file tree
Hide file tree
Showing 2 changed files with 540 additions and 0 deletions.
55 changes: 55 additions & 0 deletions pkg/karmadactl/annotate/annotate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
Copyright 2024 The Karmada Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package annotate

import (
"fmt"

"github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericiooptions"
kubectlannotate "k8s.io/kubectl/pkg/cmd/annotate"
"k8s.io/kubectl/pkg/util/templates"

"github.com/karmada-io/karmada/pkg/karmadactl/util"
)

var (
annotateExample = templates.Examples(`
# Update propagationpolicy 'foo' with the annotation 'description' and the value 'deployment dispatching'
# If the same annotation is set multiple times, only the last value will be applied
[1]%s annotate pp foo description='deployment dispatching'
# Update a propagationpolicy identified by type and name in "propagationpolicy.json"
[1]%s annotate -f propagationpolicy.json description='deployment dispatching'
# Update propagationpolicy 'foo' with the annotation 'description' and the value 'secret dispatching', overwriting any existing value
[1]%s annotate --overwrite pp foo description='secret dispatching'
# Update all propagationpolicies in the namespace
[1]%s annotate pp --all description='secret dispatching'
# Update propagationpolicy 'foo' only if the resource is unchanged from version 1
[1]%s annotate pp foo description='secret dispatching' --resource-version=1
# Update propagationpolicy 'foo' by removing an annotation named 'description' if it exists
# Does not require the --overwrite flag
[1]%s annotate pp foo description-`)
)

// NewCmdAnnotate returns new initialized instance of annotate sub command
func NewCmdAnnotate(f util.Factory, parentCommnd string, ioStreams genericiooptions.IOStreams) *cobra.Command {
cmd := kubectlannotate.NewCmdAnnotate(parentCommnd, f, ioStreams)
cmd.Example = fmt.Sprintf(annotateExample, parentCommnd)
return cmd
}
Loading

0 comments on commit 414362a

Please sign in to comment.