-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #318 from justinsb/upgrade_for_upgrade
Rename old upgrade command; make new upgrade intuitive
- Loading branch information
Showing
10 changed files
with
234 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// toolboxCmd represents the toolbox command | ||
var toolboxCmd = &cobra.Command{ | ||
Use: "toolbox", | ||
Short: "Misc infrequently used commands", | ||
} | ||
|
||
func init() { | ||
rootCommand.AddCommand(toolboxCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
"k8s.io/kops/upup/pkg/api" | ||
"k8s.io/kops/upup/pkg/fi/cloudup/awsup" | ||
"k8s.io/kops/upup/pkg/kutil" | ||
) | ||
|
||
type ConvertImportedCmd struct { | ||
NewClusterName string | ||
} | ||
|
||
var convertImported ConvertImportedCmd | ||
|
||
func init() { | ||
cmd := &cobra.Command{ | ||
Use: "convert-imported", | ||
Short: "Convert an imported cluster into a kops cluster", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
err := convertImported.Run() | ||
if err != nil { | ||
exitWithError(err) | ||
} | ||
}, | ||
} | ||
|
||
toolboxCmd.AddCommand(cmd) | ||
|
||
cmd.Flags().StringVar(&convertImported.NewClusterName, "newname", "", "new cluster name") | ||
} | ||
|
||
func (c *ConvertImportedCmd) Run() error { | ||
clusterRegistry, cluster, err := rootCommand.Cluster() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
instanceGroupRegistry, err := rootCommand.InstanceGroupRegistry() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
instanceGroups, err := instanceGroupRegistry.ReadAll() | ||
|
||
if cluster.Annotations[api.AnnotationNameManagement] != api.AnnotationValueManagementImported { | ||
return fmt.Errorf("cluster %q does not appear to be a cluster imported using kops import", cluster.Name) | ||
} | ||
|
||
if c.NewClusterName == "" { | ||
return fmt.Errorf("--newname is required for converting an imported cluster") | ||
} | ||
|
||
oldClusterName := cluster.Name | ||
if oldClusterName == "" { | ||
return fmt.Errorf("(Old) ClusterName must be set in configuration") | ||
} | ||
|
||
// TODO: Switch to cloudup.BuildCloud | ||
if len(cluster.Spec.Zones) == 0 { | ||
return fmt.Errorf("Configuration must include Zones") | ||
} | ||
|
||
region := "" | ||
for _, zone := range cluster.Spec.Zones { | ||
if len(zone.Name) <= 2 { | ||
return fmt.Errorf("Invalid AWS zone: %q", zone.Name) | ||
} | ||
|
||
zoneRegion := zone.Name[:len(zone.Name)-1] | ||
if region != "" && zoneRegion != region { | ||
return fmt.Errorf("Clusters cannot span multiple regions") | ||
} | ||
|
||
region = zoneRegion | ||
} | ||
|
||
tags := map[string]string{"KubernetesCluster": oldClusterName} | ||
cloud, err := awsup.NewAWSCloud(region, tags) | ||
if err != nil { | ||
return fmt.Errorf("error initializing AWS client: %v", err) | ||
} | ||
|
||
d := &kutil.ConvertKubeupCluster{} | ||
d.NewClusterName = c.NewClusterName | ||
d.OldClusterName = oldClusterName | ||
d.Cloud = cloud | ||
d.ClusterConfig = cluster | ||
d.InstanceGroups = instanceGroups | ||
d.ClusterRegistry = clusterRegistry | ||
|
||
err = d.Upgrade() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package api | ||
|
||
// AnnotationNameManagement is the annotation that indicates that a cluster is under external or non-standard management | ||
const AnnotationNameManagement = "kops.kubernetes.io/management" | ||
|
||
// AnnotationValueManagementImported is the annotation value that indicates a cluster was imported, typically as part of an upgrade | ||
const AnnotationValueManagementImported = "imported" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.