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