mirror of
https://github.com/1Password/onepassword-operator.git
synced 2025-10-22 07:28:06 +00:00
Add namespace
package
This commit is contained in:
@@ -127,6 +127,14 @@ func (k *Kube) Pod(selector map[string]string) *Pod {
|
||||
}
|
||||
}
|
||||
|
||||
func (k *Kube) Namespace(name string) *Namespace {
|
||||
return &Namespace{
|
||||
client: k.Client,
|
||||
config: k.Config,
|
||||
name: name,
|
||||
}
|
||||
}
|
||||
|
||||
// ApplyOnePasswordItem applies a OnePasswordItem manifest.
|
||||
func (k *Kube) ApplyOnePasswordItem(ctx context.Context, fileName string) {
|
||||
By("Applying " + fileName)
|
||||
|
41
pkg/testhelper/kube/namespace.go
Normal file
41
pkg/testhelper/kube/namespace.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package kube
|
||||
|
||||
import (
|
||||
"context"
|
||||
//nolint:staticcheck // ST1001
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
//nolint:staticcheck // ST1001
|
||||
. "github.com/onsi/gomega"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
)
|
||||
|
||||
type Namespace struct {
|
||||
client client.Client
|
||||
config *Config
|
||||
name string
|
||||
}
|
||||
|
||||
// LabelNamespace applies the given labels to the specified namespace
|
||||
func (n *Namespace) LabelNamespace(ctx context.Context, labelsMap map[string]string) {
|
||||
if labelsMap == nil || len(labelsMap) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
By("Setting labelsMap " + labels.Set(labelsMap).String() + " to namespace/" + n.name)
|
||||
ns := &corev1.Namespace{}
|
||||
err := n.client.Get(ctx, client.ObjectKey{Name: n.name}, ns)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
if ns.Labels == nil {
|
||||
ns.Labels = map[string]string{}
|
||||
}
|
||||
|
||||
for k, v := range labelsMap {
|
||||
ns.Labels[k] = v
|
||||
}
|
||||
|
||||
err = n.client.Update(ctx, ns)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
}
|
Reference in New Issue
Block a user