Skip to content

Commit

Permalink
restore flux runtime endpoint
Browse files Browse the repository at this point in the history
Signed-off-by: Eneko Fernandez <eneko@weave.works>
  • Loading branch information
enekofb committed Dec 18, 2023
1 parent 34fb77b commit 1b3a6e6
Showing 1 changed file with 11 additions and 38 deletions.
49 changes: 11 additions & 38 deletions core/server/fluxruntime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,78 +335,51 @@ func TestListFluxRuntimeObjects(t *testing.T) {
ctx := context.Background()

tests := []struct {
description string
objects []runtime.Object
gitopsRuntimeFeatureFlag string
assertions func(*pb.ListFluxRuntimeObjectsResponse)
description string
objects []runtime.Object
assertions func(*pb.ListFluxRuntimeObjectsResponse)
}{
{
"no flux runtime",
[]runtime.Object{
&corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: "ns1"}},
},
"",
func(res *pb.ListFluxRuntimeObjectsResponse) {
g.Expect(res.Errors[0].Message).To(Equal(server.ErrFluxNamespaceNotFound.Error()))
g.Expect(res.Errors[0].Namespace).To(BeEmpty())
g.Expect(res.Errors[0].ClusterName).To(Equal(cluster.DefaultCluster))
},
},
{
"use flux-system namespace when no namespace label available",
[]runtime.Object{
&corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: "flux-system"}},
newDeployment("random-flux-controller", "flux-system", map[string]string{coretypes.PartOfLabel: server.Flux}),
newDeployment("other-controller-in-flux-ns", "flux-system", map[string]string{}),
},
"",
func(res *pb.ListFluxRuntimeObjectsResponse) {
g.Expect(res.Deployments).To(HaveLen(1), "expected deployments in the default flux namespace to be returned")
g.Expect(res.Deployments[0].Name).To(Equal("random-flux-controller"))
},
},
{
"return flux runtime without WEAVE_GITOPS_FEATURE_GITOPS_RUNTIME",
"flux namespace label, with controllers",
[]runtime.Object{
&corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: "flux-ns", Labels: map[string]string{
coretypes.PartOfLabel: server.Flux,
}}},
newDeployment("random-flux-controller", "flux-ns", map[string]string{coretypes.PartOfLabel: server.Flux}),
newDeployment("other-controller-in-flux-ns", "flux-ns", map[string]string{}),
},
"false",
func(res *pb.ListFluxRuntimeObjectsResponse) {
g.Expect(res.Deployments).To(HaveLen(1), "expected deployments in the flux namespace to be returned")
g.Expect(res.Deployments[0].Name).To(Equal("random-flux-controller"))
},
},
{
"return weave gitops runtime with WEAVE_GITOPS_FEATURE_GITOPS_RUNTIME enabled",
"use flux-system namespace when no namespace label available",
[]runtime.Object{
&corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: "flux-ns", Labels: map[string]string{
coretypes.PartOfLabel: server.Flux,
}}},
newDeployment("kustomize-controller", "flux-ns", map[string]string{coretypes.PartOfLabel: server.Flux}),
newDeployment("policy-agent", "flux-ns", map[string]string{coretypes.PartOfLabel: server.WeaveGitops}),
newDeployment("other-controller-in-flux-ns", "flux-ns", map[string]string{}),
&corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: "flux-system"}},
newDeployment("random-flux-controller", "flux-system", map[string]string{coretypes.PartOfLabel: server.Flux}),
newDeployment("other-controller-in-flux-ns", "flux-system", map[string]string{}),
},
"true",
func(res *pb.ListFluxRuntimeObjectsResponse) {
g.Expect(res.Deployments).To(HaveLen(2), "expected deployments in the flux namespace to be returned")
g.Expect(res.Deployments[0].Name).To(Equal("kustomize-controller"))
g.Expect(res.Deployments[1].Name).To(Equal("policy-agent"))
g.Expect(res.Deployments).To(HaveLen(1), "expected deployments in the default flux namespace to be returned")
g.Expect(res.Deployments[0].Name).To(Equal("random-flux-controller"))
},
},
}

for _, tt := range tests {
t.Run(tt.description, func(t *testing.T) {
if tt.gitopsRuntimeFeatureFlag != "" {
_ = os.Setenv(server.GitopsRuntimeFeatureFlag, tt.gitopsRuntimeFeatureFlag)
}
defer func() {
_ = os.Unsetenv(server.GitopsRuntimeFeatureFlag)
}()
featureflags.SetFromEnv(os.Environ())
scheme, err := kube.CreateScheme()
g.Expect(err).To(BeNil())
client := fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(tt.objects...).Build()
Expand Down

0 comments on commit 1b3a6e6

Please sign in to comment.