Skip to content

Commit

Permalink
fix: allow convert-k8s --remove-initialized-keys with K8s cp is down
Browse files Browse the repository at this point in the history
The command `--remove-initialized-key` is the last resort to convert
control plane when control plane is down for whatever reason, so it
should work when control plane is not available.

Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
  • Loading branch information
smira authored and talos-bot committed Mar 25, 2021
1 parent fb605a0 commit 672c970
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
4 changes: 4 additions & 0 deletions cmd/talosctl/cmd/talos/convert-k8s.go
Expand Up @@ -24,6 +24,10 @@ Talos node configuration to reflect changes made since the boostrap time. Once c
tool releases static pods and deletes self-hosted DaemonSets.`,
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
if len(Nodes) > 0 {
convertOptions.Node = Nodes[0]
}

return WithClient(convertKubernetes)
},
}
Expand Down
12 changes: 7 additions & 5 deletions pkg/cluster/kubernetes/convert.go
Expand Up @@ -45,6 +45,8 @@ type ConvertOptions struct {
ForceYes bool
OnlyRemoveInitializedKey bool

Node string

masterNodes []string
}

Expand All @@ -58,6 +60,11 @@ type ConvertProvider interface {
//
//nolint:gocyclo,cyclop
func ConvertToStaticPods(ctx context.Context, cluster ConvertProvider, options ConvertOptions) error {
// only used in manual conversion process
if options.OnlyRemoveInitializedKey {
return removeInitializedKey(ctx, cluster, options.Node)
}

var err error

k8sClient, err := cluster.K8sHelper(ctx)
Expand All @@ -74,11 +81,6 @@ func ConvertToStaticPods(ctx context.Context, cluster ConvertProvider, options C
return fmt.Errorf("no master nodes discovered")
}

// only used in manual conversion process
if options.OnlyRemoveInitializedKey {
return removeInitializedKey(ctx, cluster, options.masterNodes[0])
}

fmt.Printf("discovered master nodes %q\n", options.masterNodes)

selfHosted, err := IsSelfHostedControlPlane(ctx, cluster, options.masterNodes[0])
Expand Down

0 comments on commit 672c970

Please sign in to comment.