Skip to content

Commit fb271c2

Browse files
Merge pull request openshift#8804 from pawanpinjarkar/log-node-image-expiry-message
AGENT-938: Enhance console logging to display node ISO expiry date during addNodes workflow
2 parents 122eed1 + 8c381ff commit fb271c2

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

data/data/agent/systemd/units/agent-auth-token-status.service

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ ExecStart=/usr/local/bin/agent-auth-token-status.sh
1111
Restart=no
1212

1313
[Install]
14-
WantedBy=multi-user.target agent-add-node.service
14+
WantedBy=agent-add-node.service

pkg/asset/agent/gencrypto/authconfig.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,26 +232,27 @@ func (a *AuthConfig) createOrUpdateAuthTokenSecret(kubeconfigPath string) error
232232
return err
233233
}
234234
// Calculate 24 hours before the expiration time
235-
thresholdTime := expiryTime.Add(-24 * time.Hour)
235+
thresholdTime := expiryTime.UTC().Add(-24 * time.Hour)
236236
// Check if current time is past the thresholdTime time of 24 hours
237237
if time.Now().UTC().After(thresholdTime) {
238238
// update the secret in the cluster with a new token from asset store
239239
err = a.refreshAuthTokenSecret(k8sclientset, retrievedSecret)
240240
if err != nil {
241241
return err
242242
}
243-
logrus.Debug("Auth token secret regenerated and updated in the cluster")
244243
} else {
245244
// Update the token in asset store with the retrieved token from the cluster
246245
a.AgentAuthToken = retrievedToken
246+
// get the token expiry time of the retrieved token from the cluster
247+
a.AgentAuthTokenExpiry = expiryTime.UTC().Format(time.RFC3339)
247248

248249
retrievedPublicKey, err := extractPublicKeyFromSecret(retrievedSecret)
249250
if err != nil {
250251
return err
251252
}
252253
// Update the asset store with the retrieved public key associated with the valid token from the cluster
253254
a.PublicKey = retrievedPublicKey
254-
logrus.Debugf("Reusing existing auth token (valid up to %s)", expiryTime)
255+
logrus.Infof("Reusing existing auth token (valid up to %s)", a.AgentAuthTokenExpiry)
255256
}
256257
return err
257258
}
@@ -261,8 +262,10 @@ func (a *AuthConfig) createSecret(k8sclientset kubernetes.Interface) error {
261262
secret := &corev1.Secret{
262263
ObjectMeta: metav1.ObjectMeta{
263264
Name: authTokenSecretName,
265+
// only for informational purposes
264266
Annotations: map[string]string{
265267
"updatedAt": "", // Initially set to empty
268+
"expiresAt": a.AgentAuthTokenExpiry,
266269
},
267270
},
268271
Type: corev1.SecretTypeOpaque,
@@ -273,9 +276,10 @@ func (a *AuthConfig) createSecret(k8sclientset kubernetes.Interface) error {
273276
}
274277
_, err := k8sclientset.CoreV1().Secrets(authTokenSecretNamespace).Create(context.Background(), secret, metav1.CreateOptions{})
275278
if err != nil {
276-
return fmt.Errorf("failed to create auth token secret: %w", err)
279+
return fmt.Errorf("failed to create secret: %w", err)
277280
}
278-
logrus.Debugf("Created auth token secret %s/%s", authTokenSecretNamespace, authTokenSecretName)
281+
logrus.Infof("Generated auth token (valid up to %s)", a.AgentAuthTokenExpiry)
282+
logrus.Infof("Created secret %s/%s", authTokenSecretNamespace, authTokenSecretName)
279283

280284
return nil
281285
}
@@ -285,12 +289,14 @@ func (a *AuthConfig) refreshAuthTokenSecret(k8sclientset kubernetes.Interface, r
285289
retrievedSecret.Data[authTokenPublicDataKey] = []byte(a.PublicKey)
286290
// only for informational purposes
287291
retrievedSecret.Annotations["updatedAt"] = time.Now().UTC().Format(time.RFC3339)
292+
retrievedSecret.Annotations["expiresAt"] = a.AgentAuthTokenExpiry
288293

289294
_, err := k8sclientset.CoreV1().Secrets(authTokenSecretNamespace).Update(context.TODO(), retrievedSecret, metav1.UpdateOptions{})
290295
if err != nil {
291296
return err
292297
}
293-
logrus.Debugf("Updated auth token secret %s/%s", authTokenSecretNamespace, authTokenSecretName)
298+
logrus.Infof("Auth token regenerated (valid up to %s)", a.AgentAuthTokenExpiry)
299+
logrus.Infof("Updated secret %s/%s", authTokenSecretNamespace, authTokenSecretName)
294300
return nil
295301
}
296302

pkg/asset/agent/image/agentimage.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/openshift/assisted-image-service/pkg/isoeditor"
1515
hiveext "github.com/openshift/assisted-service/api/hiveextension/v1beta1"
1616
"github.com/openshift/installer/pkg/asset"
17+
"github.com/openshift/installer/pkg/asset/agent/gencrypto"
1718
"github.com/openshift/installer/pkg/asset/agent/joiner"
1819
"github.com/openshift/installer/pkg/asset/agent/manifests"
1920
"github.com/openshift/installer/pkg/asset/agent/workflow"
@@ -36,6 +37,7 @@ type AgentImage struct {
3637
bootArtifactsBaseURL string
3738
platform hiveext.PlatformType
3839
isoFilename string
40+
imageExpiresAt string
3941
}
4042

4143
var _ asset.WritableAsset = (*AgentImage)(nil)
@@ -48,6 +50,7 @@ func (a *AgentImage) Dependencies() []asset.Asset {
4850
&AgentArtifacts{},
4951
&manifests.AgentManifests{},
5052
&BaseIso{},
53+
&gencrypto.AuthConfig{},
5154
}
5255
}
5356

@@ -66,8 +69,12 @@ func (a *AgentImage) Generate(ctx context.Context, dependencies asset.Parents) e
6669
a.isoFilename = agentISOFilename
6770

6871
case workflow.AgentWorkflowTypeAddNodes:
72+
authConfig := &gencrypto.AuthConfig{}
73+
dependencies.Get(authConfig)
74+
6975
a.platform = clusterInfo.PlatformType
7076
a.isoFilename = agentAddNodesISOFilename
77+
a.imageExpiresAt = authConfig.AgentAuthTokenExpiry
7178

7279
default:
7380
return fmt.Errorf("AgentWorkflowType value not supported: %s", agentWorkflow.Workflow)
@@ -218,6 +225,7 @@ func (a *AgentImage) PersistToFile(directory string) error {
218225
return err
219226
}
220227

228+
var msg string
221229
// For external platform when the bootArtifactsBaseURL is specified,
222230
// output the rootfs file alongside the minimal ISO
223231
if a.platform == hiveext.ExternalPlatformType {
@@ -237,15 +245,19 @@ func (a *AgentImage) PersistToFile(directory string) error {
237245
if err != nil {
238246
return err
239247
}
240-
logrus.Infof("Generated minimal ISO at %s", agentIsoFile)
248+
msg = fmt.Sprintf("Generated minimal ISO at %s", agentIsoFile)
241249
} else {
242250
// Generate full ISO
243251
err = isoeditor.Create(agentIsoFile, a.tmpPath, a.volumeID)
244252
if err != nil {
245253
return err
246254
}
247-
logrus.Infof("Generated ISO at %s", agentIsoFile)
255+
msg = fmt.Sprintf("Generated ISO at %s.", agentIsoFile)
256+
}
257+
if a.imageExpiresAt != "" {
258+
msg = fmt.Sprintf("%s. The ISO is valid up to %s", msg, a.imageExpiresAt)
248259
}
260+
logrus.Info(msg)
249261

250262
err = os.WriteFile(filepath.Join(directory, "rendezvousIP"), []byte(a.rendezvousIP), 0o644) //nolint:gosec // no sensitive info
251263
if err != nil {

0 commit comments

Comments
 (0)