-
Notifications
You must be signed in to change notification settings - Fork 12
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
reconcile pyxis api secret #23
Conversation
15ffac5
to
4d96ac7
Compare
4d96ac7
to
dc64a99
Compare
d866b8f
to
7557dbd
Compare
controllers/secret.go
Outdated
log.Error(err, fmt.Sprintf("unable to get the %s secret", secretName)) | ||
return err | ||
} | ||
if kubeConfigSecret.Data[KUBECONFIG_SECRET] == nil { |
There was a problem hiding this comment.
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
}
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
controllers/secret.go
Outdated
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)) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
controllers/secret.go
Outdated
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)) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 🤔
controllers/secret.go
Outdated
err = r.Client.Get(context.TODO(), key, kubeConfigSecret) | ||
if err != nil { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merged 👍
controllers/secret.go
Outdated
log.Error(err, fmt.Sprintf("unable to get the %s secret", secretName)) | ||
return err | ||
} | ||
if kubeConfigSecret.Data[KUBECONFIG_SECRET] == nil { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added an || len == 0
7557dbd
to
d7ad759
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
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