forked from janus-idp/operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into nextv2
# Conflicts: # .github/actions/docker-build/action.yaml # .github/workflows/pr.yaml # .rhdh/bundle/manifests/rhdh-operator.csv.yaml # Makefile # api/v1alpha1/backstage_types.go # bundle/manifests/backstage-default-config_v1_configmap.yaml # bundle/manifests/backstage-operator.clusterserviceversion.yaml # config/manager/default-config/db-statefulset.yaml # config/manager/default-config/deployment.yaml # config/manager/kustomization.yaml # controllers/backstage_app_config.go # controllers/backstage_backend_auth.go # controllers/backstage_controller.go # controllers/backstage_controller_test.go # controllers/backstage_deployment.go # controllers/backstage_dynamic_plugins.go # controllers/backstage_extra_envs.go # controllers/backstage_extra_files.go # controllers/backstage_route.go # controllers/backstage_service.go # controllers/local_db_secret.go # controllers/local_db_services.go # controllers/local_db_statefulset.go # controllers/local_db_storage.go # examples/bs1.yaml # integration_tests/cr-config_test.go # integration_tests/default-config_test.go # integration_tests/rhdh-config_test.go # integration_tests/route_test.go # integration_tests/suite_test.go # main.go # pkg/model/configmapenvs_test.go # pkg/model/db-secret_test.go # pkg/model/db-statefulset_test.go # pkg/model/deployment_test.go # pkg/model/dynamic-plugins_test.go # pkg/model/model_tests.go # pkg/model/route_test.go # pkg/model/runtime_test.go # pkg/model/testdata/default-config/db-secret.yaml # pkg/model/testdata/default-config/db-service.yaml # pkg/model/testdata/default-config/db-statefulset.yaml # pkg/model/testdata/janus-db-statefulset.yaml # pkg/model/testdata/janus-deployment.yaml # pkg/model/testdata/raw-cm-envs.yaml # pkg/model/testdata/raw-cm-files.yaml # pkg/model/testdata/raw-route.yaml # pkg/model/testdata/raw-secret-files.yaml # pkg/utils/pod-mutator.go
- Loading branch information
Showing
1 changed file
with
187 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
// | ||
// Copyright (c) 2023 Red Hat, Inc. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package integration_tests | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
"redhat-developer/red-hat-developer-hub-operator/pkg/utils" | ||
|
||
appsv1 "k8s.io/api/apps/v1" | ||
|
||
"sigs.k8s.io/controller-runtime/pkg/reconcile" | ||
|
||
"redhat-developer/red-hat-developer-hub-operator/pkg/model" | ||
|
||
bsv1alpha1 "redhat-developer/red-hat-developer-hub-operator/api/v1alpha1" | ||
|
||
"k8s.io/apimachinery/pkg/types" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = When("create backstage with raw configuration", func() { | ||
|
||
var ( | ||
ctx context.Context | ||
ns string | ||
) | ||
|
||
BeforeEach(func() { | ||
ctx = context.Background() | ||
ns = createNamespace(ctx) | ||
}) | ||
|
||
AfterEach(func() { | ||
// NOTE: Be aware of the current delete namespace limitations. | ||
// More info: https://book.kubebuilder.io/reference/envtest.html#testing-considerations | ||
_ = k8sClient.Delete(ctx, &corev1.Namespace{ | ||
ObjectMeta: metav1.ObjectMeta{Name: ns}, | ||
}) | ||
}) | ||
|
||
It("creates Backstage with configuration ", func() { | ||
|
||
generateConfigMap(ctx, k8sClient, "app-config1", ns, map[string]string{"key11": "app:", "key12": "app:"}) | ||
generateConfigMap(ctx, k8sClient, "app-config2", ns, map[string]string{"key21": "app:", "key22": "app:"}) | ||
|
||
generateConfigMap(ctx, k8sClient, "cm-file1", ns, map[string]string{"cm11": "11", "cm12": "12"}) | ||
generateConfigMap(ctx, k8sClient, "cm-file2", ns, map[string]string{"cm21": "21", "cm22": "22"}) | ||
|
||
generateSecret(ctx, k8sClient, "secret-file1", ns, []string{"sec11", "sec12"}) | ||
generateSecret(ctx, k8sClient, "secret-file2", ns, []string{"sec21", "sec22"}) | ||
|
||
generateConfigMap(ctx, k8sClient, "cm-env1", ns, map[string]string{"cm11": "11", "cm12": "12"}) | ||
generateConfigMap(ctx, k8sClient, "cm-env2", ns, map[string]string{"cm21": "21", "cm22": "22"}) | ||
|
||
generateSecret(ctx, k8sClient, "secret-env1", ns, []string{"sec11", "sec12"}) | ||
generateSecret(ctx, k8sClient, "secret-env2", ns, []string{"sec21", "sec22"}) | ||
|
||
bs := bsv1alpha1.BackstageSpec{ | ||
Application: &bsv1alpha1.Application{ | ||
AppConfig: &bsv1alpha1.AppConfig{ | ||
MountPath: "/my/mount/path", | ||
ConfigMaps: []bsv1alpha1.ObjectKeyRef{ | ||
{Name: "app-config1"}, | ||
{Name: "app-config2", Key: "key21"}, | ||
}, | ||
}, | ||
//DynamicPluginsConfigMapName: "", | ||
ExtraFiles: &bsv1alpha1.ExtraFiles{ | ||
MountPath: "/my/file/path", | ||
ConfigMaps: []bsv1alpha1.ObjectKeyRef{ | ||
{Name: "cm-file1"}, | ||
{Name: "cm-file2", Key: "cm21"}, | ||
}, | ||
Secrets: []bsv1alpha1.ObjectKeyRef{ | ||
{Name: "secret-file1", Key: "sec11"}, | ||
{Name: "secret-file2", Key: "sec21"}, | ||
}, | ||
}, | ||
ExtraEnvs: &bsv1alpha1.ExtraEnvs{ | ||
ConfigMaps: []bsv1alpha1.ObjectKeyRef{ | ||
{Name: "cm-env1"}, | ||
{Name: "cm-env2", Key: "cm21"}, | ||
}, | ||
Secrets: []bsv1alpha1.ObjectKeyRef{ | ||
{Name: "secret-env1", Key: "sec11"}, | ||
}, | ||
Envs: []bsv1alpha1.Env{ | ||
{Name: "env1", Value: "val1"}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
backstageName := createBackstage(ctx, bs, ns) | ||
|
||
By("Checking if the custom resource was successfully created") | ||
|
||
Eventually(func() error { | ||
found := &bsv1alpha1.Backstage{} | ||
return k8sClient.Get(ctx, types.NamespacedName{Name: backstageName, Namespace: ns}, found) | ||
}, time.Minute, time.Second).Should(Succeed()) | ||
|
||
_, err := NewTestBackstageReconciler(ns).ReconcileLocalCluster(ctx, reconcile.Request{ | ||
NamespacedName: types.NamespacedName{Name: backstageName, Namespace: ns}, | ||
}) | ||
Expect(err).To(Not(HaveOccurred())) | ||
|
||
Eventually(func(g Gomega) { | ||
deploy := &appsv1.Deployment{} | ||
err = k8sClient.Get(ctx, types.NamespacedName{Namespace: ns, Name: model.DeploymentName(backstageName)}, deploy) | ||
g.Expect(err).ShouldNot(HaveOccurred()) | ||
|
||
podSpec := deploy.Spec.Template.Spec | ||
c := podSpec.Containers[0] | ||
|
||
By("checking if app-config volumes are added to PodSpec") | ||
g.Expect(utils.GenerateVolumeNameFromCmOrSecret("app-config1")).To(BeAddedAsVolumeToPodSpec(podSpec)) | ||
g.Expect(utils.GenerateVolumeNameFromCmOrSecret("app-config2")).To(BeAddedAsVolumeToPodSpec(podSpec)) | ||
|
||
By("checking if app-config volumes are mounted to the Backstage container") | ||
g.Expect("/my/mount/path/key11").To(BeMountedToContainer(c)) | ||
g.Expect("/my/mount/path/key12").To(BeMountedToContainer(c)) | ||
g.Expect("/my/mount/path/key21").To(BeMountedToContainer(c)) | ||
g.Expect("/my/mount/path/key22").NotTo(BeMountedToContainer(c)) | ||
|
||
By("checking if app-config args are added to the Backstage container") | ||
g.Expect("/my/mount/path/key11").To(BeAddedAsArgToContainer(c)) | ||
g.Expect("/my/mount/path/key12").To(BeAddedAsArgToContainer(c)) | ||
g.Expect("/my/mount/path/key21").To(BeAddedAsArgToContainer(c)) | ||
g.Expect("/my/mount/path/key22").NotTo(BeAddedAsArgToContainer(c)) | ||
|
||
By("checking if extra-cm-file volumes are added to PodSpec") | ||
g.Expect(utils.GenerateVolumeNameFromCmOrSecret("cm-file1")).To(BeAddedAsVolumeToPodSpec(podSpec)) | ||
g.Expect(utils.GenerateVolumeNameFromCmOrSecret("cm-file2")).To(BeAddedAsVolumeToPodSpec(podSpec)) | ||
|
||
By("checking if extra-cm-file volumes are mounted to the Backstage container") | ||
g.Expect("/my/file/path/cm11").To(BeMountedToContainer(c)) | ||
g.Expect("/my/file/path/cm12").To(BeMountedToContainer(c)) | ||
g.Expect("/my/file/path/cm21").To(BeMountedToContainer(c)) | ||
g.Expect("/my/file/path/cm22").NotTo(BeMountedToContainer(c)) | ||
|
||
By("checking if extra-secret-file volumes are added to PodSpec") | ||
g.Expect(utils.GenerateVolumeNameFromCmOrSecret("secret-file1")).To(BeAddedAsVolumeToPodSpec(podSpec)) | ||
g.Expect(utils.GenerateVolumeNameFromCmOrSecret("secret-file2")).To(BeAddedAsVolumeToPodSpec(podSpec)) | ||
|
||
By("checking if extra-secret-file volumes are mounted to the Backstage container") | ||
g.Expect("/my/file/path/sec11").To(BeMountedToContainer(c)) | ||
g.Expect("/my/file/path/sec12").NotTo(BeMountedToContainer(c)) | ||
g.Expect("/my/file/path/sec21").To(BeMountedToContainer(c)) | ||
g.Expect("/my/file/path/sec22").NotTo(BeMountedToContainer(c)) | ||
|
||
By("checking if extra-envvars are injected to the Backstage container as EnvFrom") | ||
g.Expect("cm-env1").To(BeEnvFromForContainer(c)) | ||
|
||
By("checking if envarenment variables are injected to the Backstage container as EnvVar") | ||
g.Expect("env1").To(BeEnvVarForContainer(c)) | ||
g.Expect("cm21").To(BeEnvVarForContainer(c)) | ||
g.Expect("sec11").To(BeEnvVarForContainer(c)) | ||
|
||
//for _, cond := range deploy.Status.Conditions { | ||
// if cond.Type == "Available" { | ||
// g.Expect(cond.Status).To(Equal(corev1.ConditionTrue)) | ||
// } | ||
//} | ||
}, "10s", "1s").Should(Succeed()) | ||
|
||
}) | ||
}) |