@@ -21,8 +21,11 @@ import (
21
21
22
22
"github.com/pkg/errors"
23
23
"github.com/spf13/cobra"
24
+ "k8s.io/client-go/rest"
24
25
25
26
"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"
26
29
)
27
30
28
31
type moveOptions struct {
@@ -34,6 +37,7 @@ type moveOptions struct {
34
37
fromDirectory string
35
38
toDirectory string
36
39
dryRun bool
40
+ hideAPIWarnings bool
37
41
}
38
42
39
43
var mo = & moveOptions {}
@@ -80,6 +84,8 @@ func init() {
80
84
"Write Cluster API objects and all dependencies from a management cluster to directory." )
81
85
moveCmd .Flags ().StringVar (& mo .fromDirectory , "from-directory" , "" ,
82
86
"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." )
83
89
84
90
moveCmd .MarkFlagsMutuallyExclusive ("to-directory" , "to-kubeconfig" )
85
91
moveCmd .MarkFlagsMutuallyExclusive ("from-directory" , "to-directory" )
@@ -98,7 +104,34 @@ func runMove() error {
98
104
return errors .New ("please specify a target cluster using the --to-kubeconfig flag when not using --dry-run, --to-directory or --from-directory" )
99
105
}
100
106
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 ... )
102
135
if err != nil {
103
136
return err
104
137
}
0 commit comments