Skip to content

Commit 6ddfae5

Browse files
committed
make --admin configurable to rolling-update
1 parent 6aeef2c commit 6ddfae5

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

cmd/kops/rolling-update_cluster.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737
"k8s.io/kops/pkg/cloudinstances"
3838
"k8s.io/kops/pkg/commands/commandutils"
3939
"k8s.io/kops/pkg/instancegroups"
40+
"k8s.io/kops/pkg/kubeconfig"
4041
"k8s.io/kops/pkg/pretty"
4142
"k8s.io/kops/pkg/validation"
4243
"k8s.io/kops/upup/pkg/fi/cloudup"
@@ -145,6 +146,8 @@ type RollingUpdateOptions struct {
145146

146147
// TODO: Move more/all above options to RollingUpdateOptions
147148
instancegroups.RollingUpdateOptions
149+
150+
kubeconfig.CreateKubecfgOptions
148151
}
149152

150153
func (o *RollingUpdateOptions) InitDefaults() {
@@ -165,6 +168,8 @@ func (o *RollingUpdateOptions) InitDefaults() {
165168

166169
o.DrainTimeout = 15 * time.Minute
167170

171+
o.Admin = kubeconfig.DefaultKubecfgAdminLifetime
172+
168173
o.RollingUpdateOptions.InitDefaults()
169174
}
170175

@@ -193,6 +198,7 @@ func NewCmdRollingUpdateCluster(f *util.Factory, out io.Writer) *cobra.Command {
193198
cmd.Flags().BoolVar(&options.Force, "force", options.Force, "Force rolling update, even if no changes")
194199
cmd.Flags().BoolVar(&options.CloudOnly, "cloudonly", options.CloudOnly, "Perform rolling update without validating cluster status (will cause downtime)")
195200

201+
cmd.Flags().DurationVar(&options.Admin, "admin", options.Admin, "a cluster admin user credential with the specified lifetime")
196202
cmd.Flags().DurationVar(&options.ValidationTimeout, "validation-timeout", options.ValidationTimeout, "Maximum time to wait for a cluster to validate")
197203
cmd.Flags().DurationVar(&options.DrainTimeout, "drain-timeout", options.DrainTimeout, "Maximum time to wait for a node to drain")
198204
cmd.Flags().Int32Var(&options.ValidateCount, "validate-count", options.ValidateCount, "Number of times that a cluster needs to be validated after single node update")
@@ -227,6 +233,7 @@ func NewCmdRollingUpdateCluster(f *util.Factory, out io.Writer) *cobra.Command {
227233
}
228234

229235
func RunRollingUpdateCluster(ctx context.Context, f *util.Factory, out io.Writer, options *RollingUpdateOptions) error {
236+
f.CreateKubecfgOptions = options.CreateKubecfgOptions
230237
clientset, err := f.KopsClient()
231238
if err != nil {
232239
return err

cmd/kops/util/factory.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"net/url"
2424
"strings"
2525
"sync"
26-
"time"
2726

2827
"k8s.io/apimachinery/pkg/util/validation/field"
2928
"k8s.io/client-go/dynamic"
@@ -56,6 +55,8 @@ type Factory struct {
5655
mutex sync.Mutex
5756
// clusters holds REST connection configuration for connecting to clusters
5857
clusters map[string]*clusterInfo
58+
59+
kubeconfig.CreateKubecfgOptions
5960
}
6061

6162
// clusterInfo holds REST connection configuration for connecting to a cluster
@@ -66,6 +67,7 @@ type clusterInfo struct {
6667
cachedHTTPClient *http.Client
6768
cachedRESTConfig *rest.Config
6869
cachedDynamicClient dynamic.Interface
70+
kubeconfig.CreateKubecfgOptions
6971
}
7072

7173
func NewFactory(options *FactoryOptions) *Factory {
@@ -177,14 +179,15 @@ func (f *Factory) getClusterInfo(cluster *kops.Cluster) *clusterInfo {
177179

178180
func (f *Factory) RESTConfig(cluster *kops.Cluster) (*rest.Config, error) {
179181
clusterInfo := f.getClusterInfo(cluster)
182+
clusterInfo.CreateKubecfgOptions = f.CreateKubecfgOptions
180183
return clusterInfo.RESTConfig()
181184
}
182185

183186
func (f *clusterInfo) RESTConfig() (*rest.Config, error) {
184187
ctx := context.Background()
185188

186189
if f.cachedRESTConfig == nil {
187-
restConfig, err := f.factory.buildRESTConfig(ctx, f.cluster)
190+
restConfig, err := f.factory.buildRESTConfig(ctx, f.cluster, f.CreateKubecfgOptions)
188191
if err != nil {
189192
return nil, err
190193
}
@@ -253,7 +256,7 @@ func (f *Factory) VFSContext() *vfs.VFSContext {
253256
return f.vfsContext
254257
}
255258

256-
func (f *Factory) buildRESTConfig(ctx context.Context, cluster *kops.Cluster) (*rest.Config, error) {
259+
func (f *Factory) buildRESTConfig(ctx context.Context, cluster *kops.Cluster, options kubeconfig.CreateKubecfgOptions) (*rest.Config, error) {
257260
clientset, err := f.KopsClient()
258261
if err != nil {
259262
return nil, err
@@ -274,9 +277,9 @@ func (f *Factory) buildRESTConfig(ctx context.Context, cluster *kops.Cluster) (*
274277
return nil, err
275278
}
276279

277-
// Generate a relatively short-lived certificate / kubeconfig
278-
createKubecfgOptions := kubeconfig.CreateKubecfgOptions{
279-
Admin: 1 * time.Hour,
280+
// backwards compatibility
281+
if options.Admin == 0 {
282+
options.Admin = kubeconfig.DefaultKubecfgAdminLifetime
280283
}
281284

282285
conf, err := kubeconfig.BuildKubecfg(
@@ -285,7 +288,7 @@ func (f *Factory) buildRESTConfig(ctx context.Context, cluster *kops.Cluster) (*
285288
keyStore,
286289
secretStore,
287290
cloud,
288-
createKubecfgOptions,
291+
options,
289292
f.KopsStateStore())
290293
if err != nil {
291294
return nil, err

docs/cli/kops_rolling-update_cluster.md

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)