Skip to content

Commit

Permalink
wip: update helm chart
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie authored Dec 12, 2024
1 parent d0ef1cd commit eabbb7b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 13 deletions.
5 changes: 3 additions & 2 deletions api/v1alpha1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ const (
)

const (
SecretPrivateKeyName = "natz.zeiss.com/nats-private-key"
SecretSigningKeyName = "natz.zeiss.com/nats-signing-key"
SecretPrivateKeyName = "natz.zeiss.com/nats-private-key"
SecretUserCredentialsName = "natz.zeiss.com/nats-user-credentials"
SecretSigningKeyName = "natz.zeiss.com/nats-signing-key"
)

// SecretValueFromSource represents the source of a secret value
Expand Down
38 changes: 34 additions & 4 deletions controllers/natsuser_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package controllers

import (
"context"
"fmt"
"math"
"time"

Expand Down Expand Up @@ -112,9 +113,42 @@ func (r *NatsUserReconciler) reconcileResources(ctx context.Context, user *natsv
return r.ManageError(ctx, user, err)
}

if err := r.reconcileCredentials(ctx, user); err != nil {
return r.ManageError(ctx, user, err)
}

return r.ManageSuccess(ctx, user)
}

func (r *NatsUserReconciler) reconcileCredentials(ctx context.Context, user *natsv1alpha1.NatsUser) error {
secret := &corev1.Secret{}
secretName := client.ObjectKey{
Namespace: user.Namespace,
Name: fmt.Sprintf("%s-credentils", user.Name),
}

if err := r.Get(ctx, secretName, secret); !errors.IsNotFound(err) {
return err
}

secret.Name = fmt.Sprintf("%s-credentials", user.Name)
secret.Namespace = user.Namespace
secret.Type = natsv1alpha1.SecretUserCredentialsName
secret.Data = map[string][]byte{
"user.jwt": []byte(user.Status.JWT),
"user.creds": []byte(fmt.Sprintf(ACCOUNT_TEMPLATE, user.Status.JWT, user.Spec.PrivateKey.Name)),
}

_, err := controllerutil.CreateOrUpdate(ctx, r.Client, secret, func() error {
return controllerutil.SetControllerReference(user, secret, r.Scheme)
})
if err != nil {
return err
}

return nil
}

// nolint:gocyclo
func (r *NatsUserReconciler) reconcileUser(ctx context.Context, user *natsv1alpha1.NatsUser) error {
sk := &natsv1alpha1.NatsSigningKey{}
Expand Down Expand Up @@ -181,10 +215,6 @@ func (r *NatsUserReconciler) reconcileUser(ctx context.Context, user *natsv1alph
}
user.Status.JWT = jwt

if !controllerutil.ContainsFinalizer(user, natsv1alpha1.FinalizerName) {
controllerutil.AddFinalizer(user, natsv1alpha1.FinalizerName)
}

if !controllerutil.HasControllerReference(user) {
if err := controllerutil.SetControllerReference(user, pk, r.Scheme); err != nil {
return err
Expand Down
17 changes: 10 additions & 7 deletions helm/charts/account-server/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ crds:
## Globally shared configuration
global:
# -- Common labels for the all resources
additionalLabels: {}
additionalLabels:
{}
# app: natz

# Default image used by all components
Expand All @@ -35,9 +36,10 @@ global:
imagePullSecrets: []

# -- Labels for the all deployed pods
podLabels: {}
podLabels:
{}

# -- Annotations for the all deployed pods
# -- Annotations for the all deployed pods
podAnnotations: {}

# -- Toggle and define pod-level security context.
Expand All @@ -62,7 +64,7 @@ global:
## NATZ Configs
configs:

##
##

## Account Server
controller:
Expand All @@ -74,7 +76,7 @@ controller:
replicas: 1

# -- SecretName of the NATS credentials
secretName: natsoperator-sample-jwt
secretName: natsuser-system

# -- NATS configuration
nats:
Expand Down Expand Up @@ -115,9 +117,10 @@ controller:
podAnnotations: {}

# -- Labels to be added to natz controller pods
podLabels: {}
podLabels:
{}

# -- Additional volumes to the natz controller pod
# -- Additional volumes to the natz controller pod
volumes: []

# -- [Node selector]
Expand Down

0 comments on commit eabbb7b

Please sign in to comment.