All checks were successful
Build and Publish / build-release (push) Successful in 8m29s
36 lines
1.0 KiB
Go
36 lines
1.0 KiB
Go
package builder
|
|
|
|
import (
|
|
"fmt"
|
|
metadata "gitea.corredorconect.com/software-engineering/zitadel-resources-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 {
|
|
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).
|
|
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
|
|
}
|