Skip to content

Add redeem option to resource module#92

Open
AryanP123 wants to merge 1 commit intoskupperproject:mainfrom
AryanP123:redeem-token
Open

Add redeem option to resource module#92
AryanP123 wants to merge 1 commit intoskupperproject:mainfrom
AryanP123:redeem-token

Conversation

@AryanP123
Copy link
Copy Markdown

Fixes #62

@AryanP123 AryanP123 requested a review from fgiorgetti March 25, 2026 15:20
description:
- Redeem C(AccessToken) documents without keeping them in the namespace or cluster; only Secret and Link are applied.
- Other documents in the same definition are applied first. With C(spec.url) and C(spec.code), uses HTTP (as C(skupper token redeem)).
- On Kubernetes without URL/code, applies the token until the controller redeems it, then removes the AccessToken CR.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On a second thought, I believe that if platform is Kubernetes, we could just log a warning, saying that the redeem flag is only used when platform is not Kubernetes.
The Skupper V2 Controller for Kubernetes, already has the mechanisms needed to handle AccessTokens.

os.unlink(tmp)
except OSError:
pass
docs = list(yaml.safe_load_all(body))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if the order actually matters.
Maybe safer to check if the documents returned are of kinds Secret or Link.

Comment on lines +350 to +355
if fails:
self.module.fail_json(
msg="Failed to redeem {} AccessToken(s)".format(len(fails)),
redeem_failures=fails,
redeemed_link_and_secret=out or None,
)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case of a redeem failure, we should just warn users about failed AccessTokens, but not fail the module execution.
This would help to maintain idempotence, as if someone executes the module with the same resources twice, second time would return a not changed (with a warning) but not a failure.

)
return out, redeem_changed

def _redeem_kube(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I mentioned on an earlier comment, I believe we should not do it for kube and eventually just log a warning saying that the redeem flag is only relevant for non kubernetes platforms.

'''

RETURN = r'''
redeemed_link_and_secret:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a shorter name? Like redeemed_links ?

changed = k8s_client.delete(namespace, definitions)
changed = k8s.delete(namespace, definitions)
elif redeem:
wo, tokens = _split_access_tokens(definitions)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just add a warning, saying redeem is ignored for k8s?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add option to redeem AccessTokens

2 participants