@@ -77,9 +77,7 @@ func ReconcileAzureStackHCIAccess(ctx context.Context, cli client.Client, cloudF
7777 if strings .ToLower (os .Getenv ("WSSD_DEBUG_MODE" )) != "on" {
7878 _ , err := os .Stat (wssdconfigpath )
7979 if err != nil {
80- if err := login (ctx , cli , cloudFqdn ); err != nil {
81- return nil , err
82- }
80+ return login (ctx , cli , cloudFqdn )
8381 }
8482 go UpdateLoginConfig (ctx , cli )
8583 }
@@ -90,11 +88,7 @@ func ReconcileAzureStackHCIAccess(ctx context.Context, cli client.Client, cloudF
9088 return nil , errors .Wrap (err , "error: new authorizer failed" )
9189 }
9290 // Login if certificate expired
93- if err := login (ctx , cli , cloudFqdn ); err != nil {
94- return nil , err
95- }
96- // create new authorization
97- return auth .NewAuthorizerFromEnvironment (cloudFqdn )
91+ return login (ctx , cli , cloudFqdn )
9892 }
9993 return authorizer , nil
10094}
@@ -124,48 +118,50 @@ func UpdateLoginConfig(ctx context.Context, cli client.Client) {
124118
125119}
126120
127- func login (ctx context.Context , cli client.Client , cloudFqdn string ) error {
121+ func login (ctx context.Context , cli client.Client , cloudFqdn string ) (auth. Authorizer , error ) {
128122 wssdconfigpath := os .Getenv ("WSSD_CONFIG_PATH" )
129123 if wssdconfigpath == "" {
130- return errors .New ("ReconcileAzureStackHCIAccess: Environment variable WSSD_CONFIG_PATH is not set" )
124+ return nil , errors .New ("ReconcileAzureStackHCIAccess: Environment variable WSSD_CONFIG_PATH is not set" )
131125 }
132126
133127 mut .Lock ()
134128 defer mut .Unlock ()
135129 if _ , err := os .Stat (wssdconfigpath ); err == nil {
136- return nil
130+ if authorizer , err := auth .NewAuthorizerFromEnvironment (cloudFqdn ); err == nil {
131+ return authorizer , nil
132+ }
137133 }
138134 klog .Infof ("AzureStackHCI: Login attempt" )
139135 secret , err := GetSecret (ctx , cli , AzHCIAccessCreds )
140136 if err != nil {
141- return errors .Wrap (err , "failed to create wssd session, missing login credentials secret" )
137+ return nil , errors .Wrap (err , "failed to create wssd session, missing login credentials secret" )
142138 }
143139
144140 data , ok := secret .Data [AzHCIAccessTokenFieldName ]
145141 if ! ok {
146- return errors .New ("error: could not parse kubernetes secret" )
142+ return nil , errors .New ("error: could not parse kubernetes secret" )
147143 }
148144
149145 loginconfig := auth.LoginConfig {}
150146 err = config .LoadYAMLConfig (string (data ), & loginconfig )
151147 if err != nil {
152- return errors .Wrap (err , "failed to create wssd session: parse yaml login config failed" )
148+ return nil , errors .Wrap (err , "failed to create wssd session: parse yaml login config failed" )
153149 }
154150
155151 authenticationClient , err := authentication .NewAuthenticationClientAuthMode (cloudFqdn , loginconfig )
156152 if err != nil {
157- return err
153+ return nil , err
158154 }
159155
160156 _ , err = authenticationClient .LoginWithConfig (ctx , "" , loginconfig , true )
161157 if err != nil && ! azurestackhci .ResourceAlreadyExists (err ) {
162- return errors .Wrap (err , "failed to create wssd session: login failed" )
158+ return nil , errors .Wrap (err , "failed to create wssd session: login failed" )
163159 }
164160 if _ , err := os .Stat (wssdconfigpath ); err != nil {
165- return errors .Wrapf (err , "Missing wssdconfig %s after login" , wssdconfigpath )
161+ return nil , errors .Wrapf (err , "Missing wssdconfig %s after login" , wssdconfigpath )
166162 }
167163 klog .Infof ("AzureStackHCI: Login successful" )
168- return nil
164+ return auth . NewAuthorizerFromEnvironment ( cloudFqdn )
169165}
170166
171167func GetSecret (ctx context.Context , cli client.Client , name string ) (* corev1.Secret , error ) {
0 commit comments