@@ -23,6 +23,10 @@ import (
2323 "github.com/spf13/cobra"
2424
2525 "sigs.k8s.io/cluster-api/cmd/clusterctl/client"
26+ "sigs.k8s.io/cluster-api/cmd/clusterctl/client/cluster"
27+ "sigs.k8s.io/cluster-api/cmd/clusterctl/client/config"
28+ logf "sigs.k8s.io/cluster-api/cmd/clusterctl/log"
29+ "sigs.k8s.io/cluster-api/util/apiwarnings"
2630)
2731
2832type moveOptions struct {
@@ -34,6 +38,7 @@ type moveOptions struct {
3438 fromDirectory string
3539 toDirectory string
3640 dryRun bool
41+ hideAPIWarnings bool
3742}
3843
3944var mo = & moveOptions {}
@@ -80,6 +85,8 @@ func init() {
8085 "Write Cluster API objects and all dependencies from a management cluster to directory." )
8186 moveCmd .Flags ().StringVar (& mo .fromDirectory , "from-directory" , "" ,
8287 "Read Cluster API objects and all dependencies from a directory into a management cluster." )
88+ moveCmd .Flags ().BoolVar (& mo .hideAPIWarnings , "hide-api-warnings" , true ,
89+ "Hide warnings returned by the API server." )
8390
8491 moveCmd .MarkFlagsMutuallyExclusive ("to-directory" , "to-kubeconfig" )
8592 moveCmd .MarkFlagsMutuallyExclusive ("from-directory" , "to-directory" )
@@ -98,7 +105,38 @@ func runMove() error {
98105 return errors .New ("please specify a target cluster using the --to-kubeconfig flag when not using --dry-run, --to-directory or --from-directory" )
99106 }
100107
101- c , err := client .New (ctx , cfgFile )
108+ configClient , err := config .New (ctx , cfgFile )
109+ if err != nil {
110+ return err
111+ }
112+
113+ clientOptions := []client.Option {}
114+ if mo .hideAPIWarnings {
115+ clientOptions = append (clientOptions ,
116+ client .InjectClusterClientFactory (
117+ func (input client.ClusterClientFactoryInput ) (cluster.Client , error ) {
118+ return cluster .New (
119+ cluster .Kubeconfig (input .Kubeconfig ),
120+ configClient ,
121+ cluster .InjectYamlProcessor (input .Processor ),
122+ cluster .InjectProxy (
123+ cluster .NewProxy (
124+ cluster .Kubeconfig (input .Kubeconfig ),
125+ cluster .InjectWarningHandler (
126+ apiwarnings .DefaultHandler (
127+ logf .Log .WithName ("API Server Warning" ),
128+ ),
129+ ),
130+ )),
131+ ), nil
132+ },
133+ ),
134+ // Ensure that the same configClient used by both the client constructor, and the cluster client factory.
135+ client .InjectConfig (configClient ),
136+ )
137+ }
138+
139+ c , err := client .New (ctx , cfgFile , clientOptions ... )
102140 if err != nil {
103141 return err
104142 }
0 commit comments