@@ -21,8 +21,11 @@ import (
2121
2222 "github.com/pkg/errors"
2323 "github.com/spf13/cobra"
24+ "k8s.io/client-go/rest"
2425
2526 "sigs.k8s.io/cluster-api/cmd/clusterctl/client"
27+ "sigs.k8s.io/cluster-api/cmd/clusterctl/client/cluster"
28+ "sigs.k8s.io/cluster-api/cmd/clusterctl/client/config"
2629)
2730
2831type moveOptions struct {
@@ -34,6 +37,7 @@ type moveOptions struct {
3437 fromDirectory string
3538 toDirectory string
3639 dryRun bool
40+ hideAPIWarnings bool
3741}
3842
3943var mo = & moveOptions {}
@@ -80,6 +84,8 @@ func init() {
8084 "Write Cluster API objects and all dependencies from a management cluster to directory." )
8185 moveCmd .Flags ().StringVar (& mo .fromDirectory , "from-directory" , "" ,
8286 "Read Cluster API objects and all dependencies from a directory into a management cluster." )
87+ moveCmd .Flags ().BoolVar (& mo .hideAPIWarnings , "hide-api-warnings" , true ,
88+ "Hide warnings returned by the API server." )
8389
8490 moveCmd .MarkFlagsMutuallyExclusive ("to-directory" , "to-kubeconfig" )
8591 moveCmd .MarkFlagsMutuallyExclusive ("from-directory" , "to-directory" )
@@ -98,7 +104,34 @@ func runMove() error {
98104 return errors .New ("please specify a target cluster using the --to-kubeconfig flag when not using --dry-run, --to-directory or --from-directory" )
99105 }
100106
101- c , err := client .New (ctx , cfgFile )
107+ configClient , err := config .New (ctx , cfgFile )
108+ if err != nil {
109+ return err
110+ }
111+
112+ clientOptions := []client.Option {}
113+ if mo .hideAPIWarnings {
114+ clientOptions = append (clientOptions ,
115+ client .InjectClusterClientFactory (
116+ func (input client.ClusterClientFactoryInput ) (cluster.Client , error ) {
117+ return cluster .New (
118+ cluster .Kubeconfig (input .Kubeconfig ),
119+ configClient ,
120+ cluster .InjectYamlProcessor (input .Processor ),
121+ cluster .InjectProxy (
122+ cluster .NewProxy (
123+ cluster .Kubeconfig (input .Kubeconfig ),
124+ cluster .InjectWarningHandler (rest.NoWarnings {}),
125+ )),
126+ ), nil
127+ },
128+ ),
129+ // Ensure that the same configClient used by both the client constructor, and the cluster client factory.
130+ client .InjectConfig (configClient ),
131+ )
132+ }
133+
134+ c , err := client .New (ctx , cfgFile , clientOptions ... )
102135 if err != nil {
103136 return err
104137 }
0 commit comments