Skip to content

Commit

Permalink
Fix more instances where cluster could be nil
Browse files Browse the repository at this point in the history
Generally check the return value where we can't tolerate it being nil,
similar to the case seen in kubernetes#3011.
  • Loading branch information
justinsb committed Jul 24, 2017
1 parent c537c72 commit 33b351a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cmd/kops/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ func RunCreate(f *util.Factory, out io.Writer, c *CreateOptions) error {
return fmt.Errorf("error querying cluster %q: %v", clusterName, err)
}

if cluster == nil {
return fmt.Errorf("cluster %q not found", clusterName)
}

_, err = clientset.InstanceGroupsFor(cluster).Create(v)
if err != nil {
if apierrors.IsAlreadyExists(err) {
Expand Down
3 changes: 3 additions & 0 deletions cmd/kops/replace.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ func RunReplace(f *util.Factory, cmd *cobra.Command, out io.Writer, c *ReplaceOp
if err != nil {
return fmt.Errorf("error fetching cluster %q: %v", clusterName, err)
}
if cluster == nil {
return fmt.Errorf("cluster %q not found", clusterName)
}
_, err = clientset.InstanceGroupsFor(cluster).Update(v)
if err != nil {
return fmt.Errorf("error replacing instanceGroup: %v", err)
Expand Down
4 changes: 4 additions & 0 deletions cmd/kops/toolbox_convert_imported.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ func RunToolboxConvertImported(f *util.Factory, out io.Writer, options *ToolboxC
return err
}

if cluster == nil {
return fmt.Errorf("cluster %q not found", options.ClusterName)
}

list, err := clientset.InstanceGroupsFor(cluster).List(metav1.ListOptions{})
if err != nil {
return err
Expand Down
9 changes: 9 additions & 0 deletions federation/apply_federation.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ func (o *ApplyFederationOperation) FindKubecfg() (*kubeconfig.KubeconfigBuilder,
if err != nil {
return nil, fmt.Errorf("error reading cluster %q: %v", controller, err)
}
if cluster == nil {
return fmt.Errorf("cluster %q not found", controller)
}

context, err := o.federationContextForCluster(cluster)
if err != nil {
Expand Down Expand Up @@ -120,6 +123,9 @@ func (o *ApplyFederationOperation) Run() error {
if err != nil {
return fmt.Errorf("error reading cluster %q: %v", controller, err)
}
if cluster == nil {
return fmt.Errorf("cluster %q not found", controller)
}

context, err := o.federationContextForCluster(cluster)
if err != nil {
Expand Down Expand Up @@ -154,6 +160,9 @@ func (o *ApplyFederationOperation) Run() error {
if err != nil {
return fmt.Errorf("error reading cluster %q: %v", member, err)
}
if cluster == nil {
return fmt.Errorf("cluster %q not found", member)
}

clusterName := strings.Replace(cluster.Name, ".", "-", -1)

Expand Down

0 comments on commit 33b351a

Please sign in to comment.