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

reconcile pyxis api secret #23

Merged

Conversation

skattoju
Copy link
Contributor

@skattoju skattoju commented Nov 8, 2021

Fixes: #9

The pyxis api secret name can optionally be configured via the cr

This is going to have a bunch of repeated code to be addressed in #24

@openshift-ci openshift-ci bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 8, 2021
@skattoju skattoju mentioned this pull request Nov 8, 2021
@skattoju skattoju changed the title Reconcile pyxis api secret reconcile pyxis api secret Nov 8, 2021
@openshift-ci openshift-ci bot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Nov 8, 2021
@openshift-ci openshift-ci bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 8, 2021
log.Error(err, fmt.Sprintf("unable to get the %s secret", secretName))
return err
}
if kubeConfigSecret.Data[KUBECONFIG_SECRET] == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

This references the kubeconfig value. the value for this key should be
PYXIS_API_KEY = "pyxis_api_key"

Also. checking in a map this way can throw a panic if the key isn't present.

if value, ok := kubeConfigSecret.Data[KUBECONFIG_SECRET]; ok{
//then evaluate data in value
}

Copy link
Contributor Author

@skattoju skattoju Nov 8, 2021

Choose a reason for hiding this comment

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

I think if the requested key doesn’t exist, we get the value type’s zero value.. seems safe in golang ?
https://play.golang.org/p/rTtRDqMdgMa

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Missed that was the same as the secret name in the other two cases.. i think.

log.Info("existing kubeconfig secret found")
return nil // Existing Secret found, do nothing...
if !IsObjectFound(r.Client, key, secret) {
err := errors.New(fmt.Sprintf("An existing secret named %s was not found in namespace %s", secretName, meta.Namespace))
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems to be a generic error that I have seen in other files too. Can we move this error definition to a file and reuse it everywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agreed, should be fixed in #24

kubeConfigSecret := &corev1.Secret{}
err = r.Client.Get(context.TODO(), key, kubeConfigSecret)
if err != nil {
log.Error(err, fmt.Sprintf("unable to get the %s secret", secretName))
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be good to log the namespace as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

its logged right before as an info but I agree its better to include it..

have not looked into into completely but apparently the k8s runtime logging interface should be able add contextual info like namespace etc to the logs 🤔

Comment on lines 68 to 70
err = r.Client.Get(context.TODO(), key, kubeConfigSecret)
if err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

These two lines could be merged into one

Copy link
Contributor Author

Choose a reason for hiding this comment

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

merged 👍

log.Error(err, fmt.Sprintf("unable to get the %s secret", secretName))
return err
}
if kubeConfigSecret.Data[KUBECONFIG_SECRET] == nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

is there any chance that the data is not nil, but is empty? I believe we should check for the empty string as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added an || len == 0

Copy link
Collaborator

@samira-barouti samira-barouti left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Nov 8, 2021
@jomkz jomkz merged commit 79d5ede into redhat-openshift-ecosystem:main Nov 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow usage of a Red Hat Container API access key for results submission
4 participants