Skip to content

Commit 9cf1038

Browse files
committed
reduce number of if statement
Signed-off-by: Dominique Vernier <[email protected]>
1 parent c324e1a commit 9cf1038

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

pkg/cmd/accept/exec.go

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,14 @@ func (o *Options) approveCSR(kubeClient *kubernetes.Clientset, clusterName strin
120120
}
121121
//Check if already approved or denied
122122
approved, denied := GetCertApprovalCondition(&item.Status)
123-
if approved {
124-
fmt.Printf("CSR %s already approved\n", item.Name)
125-
}
123+
//if alreaady denied, then nothing to do
126124
if denied {
127125
fmt.Printf("CSR %s already denied\n", item.Name)
126+
return true, nil
128127
}
129-
//if alreaady approved or denied, then nothing to do
130-
if approved || denied {
128+
//if alreaady approved, then nothing to do
129+
if approved {
130+
fmt.Printf("CSR %s already approved\n", item.Name)
131131
return true, nil
132132
}
133133
csr = &item
@@ -178,17 +178,20 @@ func (o *Options) updateManagedCluster(clusterClient *clusterclientset.Clientset
178178
}
179179
return false, err
180180
}
181+
if mc.Spec.HubAcceptsClient {
182+
fmt.Printf("httpAcceptsClient already set for cluster %s\n", clusterName)
183+
return true, nil
184+
}
185+
if o.ClusteradmFlags.DryRun {
186+
return true, nil
187+
}
181188
if !mc.Spec.HubAcceptsClient {
182-
if !o.ClusteradmFlags.DryRun {
183-
mc.Spec.HubAcceptsClient = true
184-
_, err = clusterClient.ClusterV1().ManagedClusters().Update(context.TODO(), mc, metav1.UpdateOptions{})
185-
if err != nil {
186-
return false, err
187-
}
188-
fmt.Printf("set httpAcceptsClient to true for cluster %s\n", clusterName)
189+
mc.Spec.HubAcceptsClient = true
190+
_, err = clusterClient.ClusterV1().ManagedClusters().Update(context.TODO(), mc, metav1.UpdateOptions{})
191+
if err != nil {
192+
return false, err
189193
}
190-
} else {
191-
fmt.Printf("httpAcceptsClient already set for cluster %s\n", clusterName)
194+
fmt.Printf("set httpAcceptsClient to true for cluster %s\n", clusterName)
192195
}
193196
return true, nil
194197
}

pkg/cmd/accept/options.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ type Options struct {
1111
ClusteradmFlags *genericclioptionsclusteradm.ClusteradmFlags
1212
//A list of comma separated cluster names
1313
clusters string
14-
//Timeout to wait in second for managedcluster and CSR
14+
//Wait to wait in second for managedcluster and CSR
1515
wait int
1616
values Values
1717
}

0 commit comments

Comments
 (0)