@@ -46,11 +46,11 @@ func (o *Options) validate() error {
4646}
4747
4848func (o * Options ) run () error {
49- kubeClient , err := o .factory .KubernetesClientSet ()
49+ kubeClient , err := o .ClusteradmFlags . KubectlFactory .KubernetesClientSet ()
5050 if err != nil {
5151 return err
5252 }
53- restConfig , err := o .factory .ToRESTConfig ()
53+ restConfig , err := o .ClusteradmFlags . KubectlFactory .ToRESTConfig ()
5454 if err != nil {
5555 return err
5656 }
@@ -105,27 +105,28 @@ func (o *Options) runWithClient(kubeClient *kubernetes.Clientset, clusterClient
105105 }
106106
107107 if csr != nil {
108- if csr .Status .Conditions == nil {
109- csr .Status .Conditions = make ([]certificatesv1.CertificateSigningRequestCondition , 0 )
110- }
111-
112- csr .Status .Conditions = append (csr .Status .Conditions , certificatesv1.CertificateSigningRequestCondition {
113- Status : corev1 .ConditionTrue ,
114- Type : certificatesv1 .CertificateApproved ,
115- Reason : fmt .Sprintf ("%sApprove" , helpers .GetExampleHeader ()),
116- Message : fmt .Sprintf ("This CSR was approved by %s certificate approve." , helpers .GetExampleHeader ()),
117- LastUpdateTime : metav1 .Now (),
118- })
108+ if ! o .ClusteradmFlags .DryRun {
109+ if csr .Status .Conditions == nil {
110+ csr .Status .Conditions = make ([]certificatesv1.CertificateSigningRequestCondition , 0 )
111+ }
119112
120- kubeClient , err := o .factory .KubernetesClientSet ()
121- if err != nil {
122- return err
123- }
124- signingRequest := kubeClient .CertificatesV1 ().CertificateSigningRequests ()
125- if _ , err := signingRequest .UpdateApproval (context .TODO (), csr .Name , csr , metav1.UpdateOptions {}); err != nil {
126- return err
113+ csr .Status .Conditions = append (csr .Status .Conditions , certificatesv1.CertificateSigningRequestCondition {
114+ Status : corev1 .ConditionTrue ,
115+ Type : certificatesv1 .CertificateApproved ,
116+ Reason : fmt .Sprintf ("%sApprove" , helpers .GetExampleHeader ()),
117+ Message : fmt .Sprintf ("This CSR was approved by %s certificate approve." , helpers .GetExampleHeader ()),
118+ LastUpdateTime : metav1 .Now (),
119+ })
120+
121+ kubeClient , err := o .ClusteradmFlags .KubectlFactory .KubernetesClientSet ()
122+ if err != nil {
123+ return err
124+ }
125+ signingRequest := kubeClient .CertificatesV1 ().CertificateSigningRequests ()
126+ if _ , err := signingRequest .UpdateApproval (context .TODO (), csr .Name , csr , metav1.UpdateOptions {}); err != nil {
127+ return err
128+ }
127129 }
128-
129130 fmt .Printf ("CSR %s approved\n " , csr .Name )
130131 } else {
131132 fmt .Printf ("no CSR to approve for cluster %s\n " , clusterName )
@@ -138,16 +139,17 @@ func (o *Options) runWithClient(kubeClient *kubernetes.Clientset, clusterClient
138139 return err
139140 }
140141 if ! mc .Spec .HubAcceptsClient {
141- mc .Spec .HubAcceptsClient = true
142- _ , err = clusterClient .ClusterV1 ().ManagedClusters ().Update (context .TODO (), mc , metav1.UpdateOptions {})
143- if err != nil {
144- return err
142+ if ! o .ClusteradmFlags .DryRun {
143+ mc .Spec .HubAcceptsClient = true
144+ _ , err = clusterClient .ClusterV1 ().ManagedClusters ().Update (context .TODO (), mc , metav1.UpdateOptions {})
145+ if err != nil {
146+ return err
147+ }
145148 }
146149 fmt .Printf ("set httpAcceptsClient to true for cluster %s\n " , clusterName )
147150 } else {
148151 fmt .Printf ("httpAcceptsClient already set for cluster %s\n " , clusterName )
149152 }
150153 }
151154 return nil
152-
153155}
0 commit comments