Skip to content

Commit f456901

Browse files
committed
Fix for default value
Signed-off-by: Dominique Vernier <[email protected]>
1 parent 93b625e commit f456901

File tree

3 files changed

+27
-18
lines changed

3 files changed

+27
-18
lines changed

pkg/cmd/accept/cmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@ func NewCmd(clusteradmFlags *genericclioptionsclusteradm.ClusteradmFlags, stream
4444
}
4545

4646
cmd.Flags().StringVar(&o.clusters, "clusters", "", "Names of the cluster to accept (comma separated)")
47-
cmd.Flags().IntVar(&o.timeout, "time-out", 1, "the number of second to wait for the managedcluster and CSR")
47+
cmd.Flags().IntVar(&o.wait, "wait", 0, "the number of second to wait for the managedcluster and CSR")
4848
return cmd
4949
}

pkg/cmd/accept/exec.go

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,29 +64,38 @@ func (o *Options) run() error {
6464
return o.runWithClient(kubeClient, clusterClient)
6565
}
6666

67-
func (o *Options) runWithClient(kubeClient *kubernetes.Clientset, clusterClient *clusterclientset.Clientset) error {
67+
func (o *Options) runWithClient(kubeClient *kubernetes.Clientset, clusterClient *clusterclientset.Clientset) (err error) {
6868
for _, clusterName := range o.values.clusters {
69-
err := wait.PollImmediate(1*time.Second, time.Duration(o.timeout)*time.Second, func() (bool, error) {
70-
csrApproved, err := o.approveCSR(kubeClient, clusterName)
71-
if err != nil {
72-
return false, err
73-
}
74-
mcUpdated, err := o.updateManagedCluster(clusterClient, clusterName)
75-
if err != nil {
76-
return false, err
77-
}
78-
if csrApproved && mcUpdated {
79-
return true, nil
80-
}
81-
return false, nil
82-
})
69+
if o.wait == 0 {
70+
_, err = o.accept(kubeClient, clusterClient, clusterName)
71+
} else {
72+
err = wait.PollImmediate(1*time.Second, time.Duration(o.wait)*time.Second, func() (bool, error) {
73+
return o.accept(kubeClient, clusterClient, clusterName)
74+
})
75+
}
8376
if err != nil {
8477
return err
8578
}
8679
}
8780
return nil
8881
}
8982

83+
func (o *Options) accept(kubeClient *kubernetes.Clientset, clusterClient *clusterclientset.Clientset, clusterName string) (bool, error) {
84+
csrApproved, err := o.approveCSR(kubeClient, clusterName)
85+
if err != nil {
86+
return false, err
87+
}
88+
mcUpdated, err := o.updateManagedCluster(clusterClient, clusterName)
89+
if err != nil {
90+
return false, err
91+
}
92+
if csrApproved && mcUpdated {
93+
return true, nil
94+
}
95+
return false, nil
96+
97+
}
98+
9099
func (o *Options) approveCSR(kubeClient *kubernetes.Clientset, clusterName string) (bool, error) {
91100
csrs, err := kubeClient.CertificatesV1().CertificateSigningRequests().List(context.TODO(),
92101
metav1.ListOptions{

pkg/cmd/accept/options.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ type Options struct {
1212
//A list of comma separated cluster names
1313
clusters string
1414
//Timeout to wait in second for managedcluster and CSR
15-
timeout int
16-
values Values
15+
wait int
16+
values Values
1717
}
1818

1919
//Values: The values used in the template

0 commit comments

Comments
 (0)