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

get secrets instead of list and iterate #100

Merged
merged 2 commits into from
Apr 11, 2024
Merged
Changes from 1 commit
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
Next Next commit
do not list and iterate secrets
neoaggelos committed Apr 11, 2024

Verified

This commit was signed with the committer’s verified signature.
neoaggelos Angelos Kolaitis
commit 8d2dcf72fb5968ac1fbaab1f6cdd2465d723ea74
44 changes: 24 additions & 20 deletions controllers/microk8sconfig_controller.go
Original file line number Diff line number Diff line change
@@ -626,17 +626,19 @@ func (r *MicroK8sConfigReconciler) storeBootstrapData(ctx context.Context, scope

func (r *MicroK8sConfigReconciler) getJoinToken(ctx context.Context, scope *Scope) (string, error) {
// See if the token exists. If not create it.
secrets := &corev1.SecretList{}
err := r.Client.List(ctx, secrets)
if err != nil {
return "", err
}
secret := &corev1.Secret{}

found := false
for _, s := range secrets.Items {
if s.Name == scope.Cluster.Name+"-jointoken" {
found = true
}
var found bool
err := r.Client.Get(ctx, types.NamespacedName{
Namespace: scope.Cluster.Namespace,
Name: fmt.Sprintf("%s-jointoken", scope.Cluster.Name),
}, secret)
switch {
case err == nil:
found = true
case apierrors.IsNotFound(err):
default:
return "", err
}

if !found {
@@ -678,17 +680,19 @@ func (r *MicroK8sConfigReconciler) getJoinToken(ctx context.Context, scope *Scop

func (r *MicroK8sConfigReconciler) getCA(ctx context.Context, scope *Scope) (cert *string, key *string, err error) {
// See if the CA cert exists. If not create it.
secrets := &corev1.SecretList{}
err = r.Client.List(ctx, secrets)
if err != nil {
return nil, nil, err
}
caSecret := &corev1.Secret{}

found := false
for _, s := range secrets.Items {
if s.Name == scope.Cluster.Name+"-ca" {
found = true
}
var found bool
err = r.Client.Get(ctx, types.NamespacedName{
Namespace: scope.Cluster.Namespace,
Name: fmt.Sprintf("%s-ca", scope.Cluster.Name),
}, caSecret)
switch {
case err == nil:
found = true
case apierrors.IsNotFound(err):
default:
return nil, nil, err
}

if !found {