Skip to content

Commit

Permalink
Mark ObjectMeta as a named field
Browse files Browse the repository at this point in the history
This will work around some apimachinery bugs
(kubernetes/client-go#8)
  • Loading branch information
justinsb committed Dec 9, 2016
1 parent 23947ed commit cb5c41c
Show file tree
Hide file tree
Showing 51 changed files with 180 additions and 423 deletions.
8 changes: 4 additions & 4 deletions cmd/kops/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func RunCreate(f *util.Factory, cmd *cobra.Command, out io.Writer, c *CreateOpti
_, err = clientset.Federations().Create(v)
if err != nil {
if errors.IsAlreadyExists(err) {
return fmt.Errorf("federation %q already exists", v.Name)
return fmt.Errorf("federation %q already exists", v.ObjectMeta.Name)
}
return fmt.Errorf("error creating federation: %v", err)
}
Expand All @@ -108,20 +108,20 @@ func RunCreate(f *util.Factory, cmd *cobra.Command, out io.Writer, c *CreateOpti
_, err = clientset.Clusters().Create(v)
if err != nil {
if errors.IsAlreadyExists(err) {
return fmt.Errorf("cluster %q already exists", v.Name)
return fmt.Errorf("cluster %q already exists", v.ObjectMeta.Name)
}
return fmt.Errorf("error creating cluster: %v", err)
}

case *kopsapi.InstanceGroup:
clusterName := v.Labels[ClusterNameLabel]
clusterName := v.ObjectMeta.Labels[ClusterNameLabel]
if clusterName == "" {
return fmt.Errorf("must specify %q label with cluster name to create instanceGroup", ClusterNameLabel)
}
_, err = clientset.InstanceGroups(clusterName).Create(v)
if err != nil {
if errors.IsAlreadyExists(err) {
return fmt.Errorf("instanceGroup %q already exists", v.Name)
return fmt.Errorf("instanceGroup %q already exists", v.ObjectMeta.Name)
}
return fmt.Errorf("error creating instanceGroup: %v", err)
}
Expand Down
14 changes: 7 additions & 7 deletions cmd/kops/create_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func RunCreateCluster(f *util.Factory, cmd *cobra.Command, args []string, out io
g.Spec.Zones = []string{zone.Name}
g.Spec.MinSize = fi.Int(1)
g.Spec.MaxSize = fi.Int(1)
g.Name = "master-" + zone.Name // Subsequent masters (if we support that) could be <zone>-1, <zone>-2
g.ObjectMeta.Name = "master-" + zone.Name // Subsequent masters (if we support that) could be <zone>-1, <zone>-2
instanceGroups = append(instanceGroups, g)
masters = append(masters, g)

Expand All @@ -263,7 +263,7 @@ func RunCreateCluster(f *util.Factory, cmd *cobra.Command, args []string, out io
g.Spec.Zones = []string{zone}
g.Spec.MinSize = fi.Int(1)
g.Spec.MaxSize = fi.Int(1)
g.Name = "master-" + zone
g.ObjectMeta.Name = "master-" + zone
instanceGroups = append(instanceGroups, g)
masters = append(masters, g)
}
Expand Down Expand Up @@ -298,7 +298,7 @@ func RunCreateCluster(f *util.Factory, cmd *cobra.Command, args []string, out io
if len(nodes) == 0 {
g := &api.InstanceGroup{}
g.Spec.Role = api.InstanceGroupRoleNode
g.Name = "nodes"
g.ObjectMeta.Name = "nodes"
instanceGroups = append(instanceGroups, g)
nodes = append(nodes, g)
}
Expand Down Expand Up @@ -345,7 +345,7 @@ func RunCreateCluster(f *util.Factory, cmd *cobra.Command, args []string, out io
}

if clusterName != "" {
cluster.Name = clusterName
cluster.ObjectMeta.Name = clusterName
}

if c.KubernetesVersion != "" {
Expand Down Expand Up @@ -522,10 +522,10 @@ func RunCreateCluster(f *util.Factory, cmd *cobra.Command, args []string, out io
fmt.Fprintf(&sb, " * list clusters with: kops get cluster\n")
fmt.Fprintf(&sb, " * edit this cluster with: kops edit cluster %s\n", clusterName)
if len(nodes) > 0 {
fmt.Fprintf(&sb, " * edit your node instance group: kops edit ig --name=%s %s\n", clusterName, nodes[0].Name)
fmt.Fprintf(&sb, " * edit your node instance group: kops edit ig --name=%s %s\n", clusterName, nodes[0].ObjectMeta.Name)
}
if len(masters) > 0 {
fmt.Fprintf(&sb, " * edit your master instance group: kops edit ig --name=%s %s\n", clusterName, masters[0].Name)
fmt.Fprintf(&sb, " * edit your master instance group: kops edit ig --name=%s %s\n", clusterName, masters[0].ObjectMeta.Name)
}
fmt.Fprintf(&sb, "\n")
fmt.Fprintf(&sb, "Finally configure your cluster with: kops update cluster %s --yes\n", clusterName)
Expand All @@ -539,7 +539,7 @@ func RunCreateCluster(f *util.Factory, cmd *cobra.Command, args []string, out io
glog.Infof("Exporting kubecfg for cluster")

x := &kutil.CreateKubecfg{
ContextName: cluster.Name,
ContextName: cluster.ObjectMeta.Name,
KeyStore: keyStore,
SecretStore: secretStore,
KubeMasterIP: cluster.Spec.MasterPublicName,
Expand Down
6 changes: 3 additions & 3 deletions cmd/kops/create_ig.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func RunCreateInstanceGroup(f *util.Factory, cmd *cobra.Command, args []string,
return err
}

existing, err := clientset.InstanceGroups(cluster.Name).Get(groupName)
existing, err := clientset.InstanceGroups(cluster.ObjectMeta.Name).Get(groupName)
if err != nil {
return err
}
Expand All @@ -83,7 +83,7 @@ func RunCreateInstanceGroup(f *util.Factory, cmd *cobra.Command, args []string,

// Populate some defaults
ig := &api.InstanceGroup{}
ig.Name = groupName
ig.ObjectMeta.Name = groupName
ig.Spec.Role = api.InstanceGroupRoleNode

ig, err = cloudup.PopulateInstanceGroupSpec(cluster, ig, channel)
Expand Down Expand Up @@ -123,7 +123,7 @@ func RunCreateInstanceGroup(f *util.Factory, cmd *cobra.Command, args []string,
return err
}

_, err = clientset.InstanceGroups(cluster.Name).Create(group)
_, err = clientset.InstanceGroups(cluster.ObjectMeta.Name).Create(group)
if err != nil {
return fmt.Errorf("error storing InstanceGroup: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/kops/delete_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (c *DeleteClusterCmd) Run(args []string) error {
return fmt.Errorf("cluster %q not found", clusterName)
}

if clusterName != cluster.Name {
if clusterName != cluster.ObjectMeta.Name {
return fmt.Errorf("sanity check failed: cluster name mismatch")
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/kops/delete_instancegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (c *DeleteInstanceceGroupCmd) Run(groupName string) error {
return err
}

group, err := clientset.InstanceGroups(cluster.Name).Get(groupName)
group, err := clientset.InstanceGroups(cluster.ObjectMeta.Name).Get(groupName)
if err != nil {
return fmt.Errorf("error reading InstanceGroup %q: %v", groupName, err)
}
Expand All @@ -90,7 +90,7 @@ func (c *DeleteInstanceceGroupCmd) Run(groupName string) error {
return err
}

fmt.Printf("InstanceGroup %q deleted\n", group.Name)
fmt.Printf("InstanceGroup %q deleted\n", group.ObjectMeta.Name)

return nil
}
2 changes: 1 addition & 1 deletion cmd/kops/edit_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func RunEditCluster(f *util.Factory, cmd *cobra.Command, args []string, out io.W
return err
}

list, err := clientset.InstanceGroups(oldCluster.Name).List(k8sapi.ListOptions{})
list, err := clientset.InstanceGroups(oldCluster.ObjectMeta.Name).List(k8sapi.ListOptions{})
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/kops/edit_instancegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func RunEditInstanceGroup(f *util.Factory, cmd *cobra.Command, args []string, ou
return fmt.Errorf("name is required")
}

oldGroup, err := clientset.InstanceGroups(cluster.Name).Get(groupName)
oldGroup, err := clientset.InstanceGroups(cluster.ObjectMeta.Name).Get(groupName)
if err != nil {
return fmt.Errorf("error reading InstanceGroup %q: %v", groupName, err)
}
Expand Down Expand Up @@ -150,7 +150,7 @@ func RunEditInstanceGroup(f *util.Factory, cmd *cobra.Command, args []string, ou
}

// Note we perform as much validation as we can, before writing a bad config
_, err = clientset.InstanceGroups(cluster.Name).Update(fullGroup)
_, err = clientset.InstanceGroups(cluster.ObjectMeta.Name).Update(fullGroup)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/kops/export_kubecfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (c *ExportKubecfgCommand) Run(args []string) error {
return err
}

clusterName := cluster.Name
clusterName := cluster.ObjectMeta.Name

master := cluster.Spec.MasterPublicName
if master == "" {
Expand Down
10 changes: 5 additions & 5 deletions cmd/kops/get_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (c *GetClustersCmd) Run(args []string) error {
m := make(map[string]*api.Cluster)
for i := range clusterList.Items {
c := &clusterList.Items[i]
m[c.Name] = c
m[c.ObjectMeta.Name] = c
}
for _, arg := range args {
ig := m[arg]
Expand All @@ -94,7 +94,7 @@ func (c *GetClustersCmd) Run(args []string) error {
if output == OutputTable {
t := &tables.Table{}
t.AddColumn("NAME", func(c *api.Cluster) string {
return c.Name
return c.ObjectMeta.Name
})
t.AddColumn("CLOUD", func(c *api.Cluster) string {
return c.Spec.CloudProvider
Expand All @@ -113,12 +113,12 @@ func (c *GetClustersCmd) Run(args []string) error {
for _, cluster := range clusters {
configBase, err := registry.ConfigBase(cluster)
if err != nil {
return fmt.Errorf("error reading full cluster spec for %q: %v", cluster.Name, err)
return fmt.Errorf("error reading full cluster spec for %q: %v", cluster.ObjectMeta.Name, err)
}
fullSpec := &api.Cluster{}
err = registry.ReadConfigDeprecated(configBase.Join(registry.PathClusterCompleted), fullSpec)
if err != nil {
return fmt.Errorf("error reading full cluster spec for %q: %v", cluster.Name, err)
return fmt.Errorf("error reading full cluster spec for %q: %v", cluster.ObjectMeta.Name, err)
}
fullSpecs = append(fullSpecs, fullSpec)
}
Expand All @@ -128,7 +128,7 @@ func (c *GetClustersCmd) Run(args []string) error {
for _, cluster := range clusters {
y, err := api.ToYaml(cluster)
if err != nil {
return fmt.Errorf("error marshaling yaml for %q: %v", cluster.Name, err)
return fmt.Errorf("error marshaling yaml for %q: %v", cluster.ObjectMeta.Name, err)
}
_, err = os.Stdout.Write(y)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/kops/get_federation.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func RunGetFederations(context Factory, out io.Writer, options *GetFederationOpt
if output == OutputTable {
t := &tables.Table{}
t.AddColumn("NAME", func(f *api.Federation) string {
return f.Name
return f.ObjectMeta.Name
})
t.AddColumn("CONTROLLERS", func(f *api.Federation) string {
return strings.Join(f.Spec.Controllers, ",")
Expand All @@ -86,7 +86,7 @@ func RunGetFederations(context Factory, out io.Writer, options *GetFederationOpt
for _, f := range federations {
y, err := api.ToYaml(f)
if err != nil {
return fmt.Errorf("error marshaling yaml for %q: %v", f.Name, err)
return fmt.Errorf("error marshaling yaml for %q: %v", f.ObjectMeta.Name, err)
}
_, err = out.Write(y)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions cmd/kops/get_instancegroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (c *GetInstanceGroupsCmd) Run(args []string) error {
m := make(map[string]*api.InstanceGroup)
for i := range list.Items {
ig := &list.Items[i]
m[ig.Name] = ig
m[ig.ObjectMeta.Name] = ig
}
instancegroups = make([]*api.InstanceGroup, 0, len(args))
for _, arg := range args {
Expand All @@ -97,7 +97,7 @@ func (c *GetInstanceGroupsCmd) Run(args []string) error {
if output == OutputTable {
t := &tables.Table{}
t.AddColumn("NAME", func(c *api.InstanceGroup) string {
return c.Name
return c.ObjectMeta.Name
})
t.AddColumn("ROLE", func(c *api.InstanceGroup) string {
return string(c.Spec.Role)
Expand All @@ -119,7 +119,7 @@ func (c *GetInstanceGroupsCmd) Run(args []string) error {
for _, ig := range instancegroups {
y, err := api.ToYaml(ig)
if err != nil {
return fmt.Errorf("error marshaling yaml for %q: %v", ig.Name, err)
return fmt.Errorf("error marshaling yaml for %q: %v", ig.ObjectMeta.Name, err)
}
_, err = os.Stdout.Write(y)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions cmd/kops/rollingupdate_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (c *RollingUpdateClusterCmd) Run(args []string) error {
return err
}

contextName := cluster.Name
contextName := cluster.ObjectMeta.Name
config, err := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
clientcmd.NewDefaultClientConfigLoadingRules(),
&clientcmd.ConfigOverrides{CurrentContext: contextName}).ClientConfig()
Expand Down Expand Up @@ -112,7 +112,7 @@ func (c *RollingUpdateClusterCmd) Run(args []string) error {
}
}

list, err := clientset.InstanceGroups(cluster.Name).List(k8sapi.ListOptions{})
list, err := clientset.InstanceGroups(cluster.ObjectMeta.Name).List(k8sapi.ListOptions{})
if err != nil {
return err
}
Expand Down Expand Up @@ -142,7 +142,7 @@ func (c *RollingUpdateClusterCmd) Run(args []string) error {
{
t := &tables.Table{}
t.AddColumn("NAME", func(r *kutil.CloudInstanceGroup) string {
return r.InstanceGroup.Name
return r.InstanceGroup.ObjectMeta.Name
})
t.AddColumn("STATUS", func(r *kutil.CloudInstanceGroup) string {
return r.Status
Expand Down
4 changes: 2 additions & 2 deletions cmd/kops/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ func (c *RootCmd) Cluster() (*kopsapi.Cluster, error) {
return nil, fmt.Errorf("cluster %q not found", clusterName)
}

if clusterName != cluster.Name {
return nil, fmt.Errorf("cluster name did not match expected name: %v vs %v", clusterName, cluster.Name)
if clusterName != cluster.ObjectMeta.Name {
return nil, fmt.Errorf("cluster name did not match expected name: %v vs %v", clusterName, cluster.ObjectMeta.Name)
}
return cluster, nil
}
8 changes: 4 additions & 4 deletions cmd/kops/toolbox_convert_imported.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (c *ConvertImportedCmd) Run() error {
return err
}

list, err := clientset.InstanceGroups(cluster.Name).List(k8sapi.ListOptions{})
list, err := clientset.InstanceGroups(cluster.ObjectMeta.Name).List(k8sapi.ListOptions{})
if err != nil {
return err
}
Expand All @@ -72,15 +72,15 @@ func (c *ConvertImportedCmd) Run() error {
instanceGroups = append(instanceGroups, &list.Items[i])
}

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 cluster.ObjectMeta.Annotations[api.AnnotationNameManagement] != api.AnnotationValueManagementImported {
return fmt.Errorf("cluster %q does not appear to be a cluster imported using kops import", cluster.ObjectMeta.Name)
}

if c.NewClusterName == "" {
return fmt.Errorf("--newname is required for converting an imported cluster")
}

oldClusterName := cluster.Name
oldClusterName := cluster.ObjectMeta.Name
if oldClusterName == "" {
return fmt.Errorf("(Old) ClusterName must be set in configuration")
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/kops/update_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func RunUpdateCluster(f *util.Factory, cmd *cobra.Command, args []string, out io
}

if c.SSHPublicKey != "" {
fmt.Fprintf(out, "--ssh-public-key on update is deprecated - please use `kops create secret --name %s sshpublickey admin -i ~/.ssh/id_rsa.pub` instead\n", cluster.Name)
fmt.Fprintf(out, "--ssh-public-key on update is deprecated - please use `kops create secret --name %s sshpublickey admin -i ~/.ssh/id_rsa.pub` instead\n", cluster.ObjectMeta.Name)

c.SSHPublicKey = utils.ExpandPath(c.SSHPublicKey)
authorized, err := ioutil.ReadFile(c.SSHPublicKey)
Expand Down Expand Up @@ -153,7 +153,7 @@ func RunUpdateCluster(f *util.Factory, cmd *cobra.Command, args []string, out io

// TODO: Only if not yet set?
if !isDryrun {
hasKubecfg, err := hasKubecfg(cluster.Name)
hasKubecfg, err := hasKubecfg(cluster.ObjectMeta.Name)
if err != nil {
glog.Warningf("error reading kubecfg: %v", err)
hasKubecfg = true
Expand All @@ -168,7 +168,7 @@ func RunUpdateCluster(f *util.Factory, cmd *cobra.Command, args []string, out io
if kubecfgCert != nil {
glog.Infof("Exporting kubecfg for cluster")
x := &kutil.CreateKubecfg{
ContextName: cluster.Name,
ContextName: cluster.ObjectMeta.Name,
KeyStore: keyStore,
SecretStore: secretStore,
KubeMasterIP: cluster.Spec.MasterPublicName,
Expand Down
Loading

0 comments on commit cb5c41c

Please sign in to comment.