Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle the case where GetCluster returns nil #3038

Merged
merged 2 commits into from
Jul 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 4 additions & 0 deletions cmd/kops/get_instancegroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ func RunGetInstanceGroups(options *GetInstanceGroupsOptions, args []string) erro
return fmt.Errorf("error fetching cluster %q: %v", clusterName, err)
}

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

list, err := clientset.InstanceGroupsFor(cluster).List(metav1.ListOptions{})
if err != nil {
return 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 nil, 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