Skip to content

Commit f2f2a60

Browse files
[WIP]
Signed-off-by: Alexandre Lamarre <alexandre.lamarre@suse.com>
1 parent fc4d0c3 commit f2f2a60

File tree

6 files changed

+132
-15
lines changed

6 files changed

+132
-15
lines changed

go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ require (
3838
)
3939

4040
// TODO: remove
41-
replace (
42-
github.com/rancher/lasso => /home/alex/forks/lasso
43-
github.com/rancher/wrangler/v3 => /home/alex/forks/wrangler
44-
)
41+
// replace (
42+
// github.com/rancher/lasso => /home/alex/forks/lasso
43+
// github.com/rancher/wrangler/v3 => /home/alex/forks/wrangler
44+
// )
4545

4646
require (
4747
emperror.dev/errors v0.8.1 // indirect

go.sum

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@ github.com/prometheus/common v0.61.0 h1:3gv/GThfX0cV2lpO7gkTUwZru38mxevy90Bj8YFS
187187
github.com/prometheus/common v0.61.0/go.mod h1:zr29OCN/2BsJRaFwG8QOBr41D6kkchKbpeNH7pAjb/s=
188188
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
189189
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
190+
github.com/rancher/lasso v0.2.1 h1:SZTqMVQn8cAOqvwGBd1/EYOIJ/MGN+UfJrOWvHd4jHU=
191+
github.com/rancher/lasso v0.2.1/go.mod h1:KSV3jBXfdXqdCuMm2uC8kKB9q/wuDYb3h0eHZoRjShM=
192+
github.com/rancher/wrangler/v3 v3.2.0-rc.2 h1:weBa8NvAPFKFfkg3ZeD+V+B4yxCpaoiM9rPbvONKBVQ=
193+
github.com/rancher/wrangler/v3 v3.2.0-rc.2/go.mod h1:Py71XA9ENufjKSGHr9n/pk+iMB6vU5ZrD1EOu9Q9nIs=
190194
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
191195
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
192196
github.com/rubenv/sql-migrate v1.5.2 h1:bMDqOnrJVV/6JQgQ/MxOpU+AdO8uzYYA/TxFUBzFtS0=
@@ -241,8 +245,6 @@ go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0 h1:3Q/xZUyC1BBkualc9RO
241245
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0/go.mod h1:s75jGIWA9OfCMzF0xr+ZgfrB5FEbbV7UuYo32ahUiFI=
242246
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.27.0 h1:qFffATk0X+HD+f1Z8lswGiOQYKHRlzfmdJm0wEaVrFA=
243247
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.27.0/go.mod h1:MOiCmryaYtc+V0Ei+Tx9o5S1ZjA7kzLucuVuyzBZloQ=
244-
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.34.0 h1:jBpDk4HAUsrnVO1FsfCfCOTEc/MkInJmvfCHYLFiT80=
245-
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.34.0/go.mod h1:H9LUIM1daaeZaz91vZcfeM0fejXPmgCYE8ZhzqfJuiU=
246248
go.opentelemetry.io/otel/metric v1.34.0 h1:+eTR3U0MyfWjRDhmFMxe2SsW64QrZ84AOhvqS7Y+PoQ=
247249
go.opentelemetry.io/otel/metric v1.34.0/go.mod h1:CEDrp0fy2D0MvkXE+dPV7cMi8tWZwX3dmaIhwPOaqHE=
248250
go.opentelemetry.io/otel/sdk v1.34.0 h1:95zS4k/2GOy069d321O8jWgYsW3MzVV+KuSPKp7Wr1A=

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)