Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update harvester cloud cred expiration annotation, improve renew function #12203

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion shell/config/labels-annotations.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,5 +174,5 @@ export const SYSTEM_LABELS = [
];

export const CLOUD_CREDENTIALS = [
'cattle.io/expiration-timestamp'
'rancher.io/expiration-timestamp',
];
32 changes: 16 additions & 16 deletions shell/models/cloudcredential.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,26 @@ const renew = {
},
renewBulk: async({ cloudCredentials, $ctx }) => {
// A harvester cloud credential (at the moment) is a kubeconfig complete with expiring token
// So to renew we just need to generate a new one and save it to the cc (similar to shell/cloud-credential/harvester.vue)
// So to renew we just need to generate a new kubeconfig and save it to the cc (similar to shell/cloud-credential/harvester.vue)
await Promise.all(cloudCredentials.map(async(cc) => {
try {
if (!cc.harvestercredentialConfig?.clusterId) {
throw new Error(`credential has no matching harvester cluster`);
}
const mgmtCluster = $ctx.rootGetters['management/byId'](MANAGEMENT.CLUSTER, cc.harvestercredentialConfig.clusterId);

const mgmtClusters = $ctx.rootGetters['management/all'](MANAGEMENT.CLUSTER);
if (!mgmtCluster) {
throw new Error(`cannot find harvester cluster`);
}

await Promise.all(cloudCredentials.map((cc) => {
const mgmtCluster = mgmtClusters.find((x) => x.id === cc.harvestercredentialConfig?.clusterId);
const kubeconfigContent = await mgmtCluster.generateKubeConfig();

if (!mgmtCluster) {
throw new Error(`Unable to refresh credentials cloud credential '${ cc.id }'`);
}
cc.setData('kubeconfigContent', kubeconfigContent);

return mgmtCluster.generateKubeConfig()
.then((kubeconfigContent) => {
cc.setData('kubeconfigContent', kubeconfigContent);

return cc.save();
})
.catch((err) => {
console.error('Unable to save cloud credential', err); // eslint-disable-line no-console
});
await cc.save();
} catch (error) {
console.error(`Unable to refresh harvester cloud credential '${ cc.id }'`, error); // eslint-disable-line no-console
}
}));
}
}
Expand Down
Loading