This commit is contained in:
38
pkg/builder/secret_builder.go
Normal file
38
pkg/builder/secret_builder.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package builder
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
zitadelv1alpha1 "gitea.corredorconect.com/software-engineering/zitadel-k8s-operator/api/v1alpha1"
|
||||
metadata "gitea.corredorconect.com/software-engineering/zitadel-k8s-operator/pkg/builder/metadata"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
|
||||
)
|
||||
|
||||
type SecretOpts struct {
|
||||
Zitadel *zitadelv1alpha1.Cluster
|
||||
Key types.NamespacedName
|
||||
Data map[string][]byte
|
||||
Labels map[string]string
|
||||
Annotations map[string]string
|
||||
Immutable bool
|
||||
}
|
||||
|
||||
func (b *Builder) BuildSecret(opts SecretOpts, owner metav1.Object) (*corev1.Secret, error) {
|
||||
objMeta :=
|
||||
metadata.NewMetadataBuilder(opts.Key).
|
||||
WithZitadel(opts.Zitadel).
|
||||
WithLabels(opts.Labels).
|
||||
WithAnnotations(opts.Annotations).
|
||||
Build()
|
||||
secret := &corev1.Secret{
|
||||
ObjectMeta: objMeta,
|
||||
Data: opts.Data,
|
||||
Immutable: &opts.Immutable,
|
||||
}
|
||||
if err := controllerutil.SetControllerReference(owner, secret, b.scheme); err != nil {
|
||||
return nil, fmt.Errorf("error setting controller reference in Secret manifest: %v", err)
|
||||
}
|
||||
return secret, nil
|
||||
}
|
||||
Reference in New Issue
Block a user