Skip to content

Commit 8875e48

Browse files
test : indeed WIP
Signed-off-by: Alexandre Lamarre <alexandre.lamarre@suse.com>
1 parent 6f2fbc4 commit 8875e48

File tree

4 files changed

+124
-9
lines changed

4 files changed

+124
-9
lines changed

internal/helm-project-operator/controllers/project/integration.go

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package project
22

33
import (
44
"context"
5+
"fmt"
56

67
. "github.com/onsi/ginkgo/v2"
78
. "github.com/onsi/gomega"
@@ -10,6 +11,8 @@ import (
1011
"github.com/rancher/prometheus-federator/internal/helm-project-operator/controllers/namespace"
1112
"github.com/rancher/prometheus-federator/internal/helm-project-operator/controllers/setup"
1213
"github.com/rancher/prometheus-federator/internal/test"
14+
corev1 "k8s.io/api/core/v1"
15+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1316
// . "github.com/kralicky/kmatch"
1417
)
1518

@@ -62,7 +65,7 @@ func ProjectControllerTest(
6265
)
6366

6467
// TODO : https://github.com/rancher/prometheus-federator/pull/166
65-
By("verifying registed role bindings")
68+
By("verifying registered role bindings")
6669

6770
By("starting all controllers")
6871
ctxca, ca := context.WithCancel(t.Context())
@@ -72,7 +75,41 @@ func ProjectControllerTest(
7275
})
7376

7477
When("the controller is running", func() {
75-
It("should do something", func() {
78+
Specify("when we create a project helm chart", func() {
79+
dummyRegistrationNamespace := fmt.Sprintf(
80+
common.ProjectRegistrationNamespaceFmt,
81+
"dummy-registration-namespace",
82+
)
83+
projectId := "dumb-1"
84+
ns := &corev1.Namespace{
85+
ObjectMeta: metav1.ObjectMeta{
86+
Name: dummyRegistrationNamespace,
87+
Labels: map[string]string{
88+
opts.ProjectLabel: projectId,
89+
},
90+
},
91+
}
92+
// t.ObjectTracker().Add(ns)
93+
Expect(t.K8sClient().Create(t.Context(), ns)).To(Succeed())
94+
95+
ph := &v1alpha1.ProjectHelmChart{
96+
ObjectMeta: metav1.ObjectMeta{
97+
Name: "hello",
98+
Namespace: dummyRegistrationNamespace,
99+
},
100+
Spec: v1alpha1.ProjectHelmChartSpec{
101+
HelmAPIVersion: opts.HelmAPIVersion,
102+
Values: map[string]interface{}{
103+
"enabled": "true",
104+
},
105+
},
106+
}
107+
// t.ObjectTracker().Add(ph)
108+
Expect(t.K8sClient().Create(t.Context(), ph)).To(Succeed())
109+
110+
Eventually(func() error {
111+
return nil
112+
}).Should(Succeed())
76113
})
77114
})
78115

internal/integration/examples/foo-chart/templates/configmap.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ metadata:
55
namespace: {{ .Release.Namespace }}
66
data:
77
"contents" : {{ .Values.contents}}
8+
"contents2" : {{ .Values.contents2}}

internal/integration/integration_test.go

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
helm_locker "github.com/rancher/prometheus-federator/internal/helm-locker"
66
"github.com/rancher/prometheus-federator/internal/helm-project-operator/controllers/common"
77
"github.com/rancher/prometheus-federator/internal/helm-project-operator/controllers/namespace"
8+
"github.com/rancher/prometheus-federator/internal/helm-project-operator/controllers/project"
89
"github.com/rancher/prometheus-federator/internal/test"
910
"github.com/rancher/prometheus-federator/pkg/instrumentation"
1011
)
@@ -20,10 +21,8 @@ const overrideProjectLabel = "x.y.z/projectId"
2021
var _ = BeforeSuite(test.Setup)
2122

2223
var _ = Describe("Prometheus Federator integration tests", Ordered, func() {
23-
Describe("HPO/SingleNamespaceController", Ordered, namespace.SingleNamespaceTest())
24-
// TODO : discuss whether or not we should allow helm-project-operator to sync invalid yaml
25-
// to questions/values project registration namespaces
26-
Describe("HPO/MultiNamespaceController/InvalidYaml", Ordered, namespace.MultiNamespaceTest(
24+
Describe("HPO/NamespaceController/Single", Ordered, namespace.SingleNamespaceTest())
25+
Describe("HPO/NamespaceController/InvalidYaml", Ordered, namespace.MultiNamespaceTest(
2726
"cattle-helm-system",
2827
common.Options{
2928
OperatorOptions: common.OperatorOptions{
@@ -44,7 +43,7 @@ var _ = Describe("Prometheus Federator integration tests", Ordered, func() {
4443
"questions?",
4544
"project-id-1",
4645
))
47-
Describe("HPO/MultiNamespaceController/ValidYaml", Ordered, namespace.MultiNamespaceTest(
46+
Describe("HPO/NamespaceController/ValidYaml", Ordered, namespace.MultiNamespaceTest(
4847
"cattle-helm-system",
4948
common.Options{
5049
OperatorOptions: common.OperatorOptions{
@@ -64,8 +63,29 @@ var _ = Describe("Prometheus Federator integration tests", Ordered, func() {
6463
validValuesYaml,
6564
emptyQuestions,
6665
"project-id-2",
67-
),
68-
)
66+
))
67+
Describe("HPO/ProjectController", Ordered, project.ProjectControllerTest(
68+
"cattle-helm-system",
69+
common.Options{
70+
OperatorOptions: common.OperatorOptions{
71+
HelmAPIVersion: "v1",
72+
ReleaseName: "test-1",
73+
// TODO : set this to a valid chart content
74+
ChartContent: "",
75+
},
76+
RuntimeOptions: common.RuntimeOptions{
77+
ProjectLabel: projectIdLabel,
78+
},
79+
},
80+
map[string]interface{}{
81+
"contents2": "alwaysOverriden",
82+
},
83+
projectGetter(
84+
[]string{},
85+
[]string{},
86+
map[string][]string{},
87+
),
88+
))
6989
Describe("HelmLocker/e2e", Ordered, helm_locker.E2eTest())
7090
})
7191

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package integration
2+
3+
import (
4+
"slices"
5+
6+
v1alpha1 "github.com/rancher/prometheus-federator/internal/helm-project-operator/apis/helm.cattle.io/v1alpha1"
7+
"github.com/rancher/prometheus-federator/internal/helm-project-operator/controllers/namespace"
8+
corev1 "k8s.io/api/core/v1"
9+
)
10+
11+
type embedProjectGetter struct {
12+
projRegistration []string
13+
system []string
14+
targetNamespaces map[string][]string
15+
}
16+
17+
func (e *embedProjectGetter) IsProjectRegistrationNamespace(namespace *corev1.Namespace) bool {
18+
if namespace == nil {
19+
return false
20+
}
21+
return slices.Contains(e.projRegistration, namespace.Name)
22+
}
23+
24+
func (e *embedProjectGetter) IsSystemNamespace(namespace *corev1.Namespace) bool {
25+
if namespace == nil {
26+
return false
27+
}
28+
return slices.Contains(e.system, namespace.Name)
29+
}
30+
31+
// GetTargetProjectNamespaces returns the list of namespaces that should be targeted for a given ProjectHelmChart
32+
// Any namespace returned by this should not be a project registration namespace or a system namespace
33+
func (e *embedProjectGetter) GetTargetProjectNamespaces(projectHelmChart *v1alpha1.ProjectHelmChart) ([]string, error) {
34+
if projectHelmChart == nil {
35+
return []string{}, nil
36+
}
37+
vals, ok := e.targetNamespaces[projectHelmChart.Name]
38+
if !ok {
39+
return []string{}, nil
40+
}
41+
return vals, nil
42+
}
43+
44+
var _ namespace.ProjectGetter = (*embedProjectGetter)(nil)
45+
46+
func projectGetter(
47+
projRegistration []string,
48+
system []string,
49+
targetNamespaces map[string][]string,
50+
) namespace.ProjectGetter {
51+
52+
return &embedProjectGetter{
53+
projRegistration: projRegistration,
54+
system: system,
55+
targetNamespaces: targetNamespaces,
56+
}
57+
}

0 commit comments

Comments
 (0)