Skip to content

Commit

Permalink
chore: remove ownruntime flag (#372)
Browse files Browse the repository at this point in the history
* remove ownruntime flag

Signed-off-by: gazarenkov <gazarenkov@gmail.com>

* fix

Signed-off-by: gazarenkov <gazarenkov@gmail.com>

---------

Signed-off-by: gazarenkov <gazarenkov@gmail.com>
  • Loading branch information
gazarenkov authored Oct 31, 2024
1 parent 1f079fa commit bac4fc5
Show file tree
Hide file tree
Showing 15 changed files with 58 additions and 68 deletions.
5 changes: 0 additions & 5 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ func main() {
var probeAddr string
var secureMetrics bool
var enableHTTP2 bool
var ownRuntime bool
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080",
"The address the metrics endpoint binds to. Use 0 to disable the metrics service.")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
Expand All @@ -58,8 +57,6 @@ func main() {
"If set, the metrics endpoint is served securely over HTTPS and requires authentication and authorization.")
flag.BoolVar(&enableHTTP2, "enable-http2", false,
"If set, HTTP/2 will be enabled for the metrics and webhook servers")
flag.BoolVar(&ownRuntime, "own-runtime", true, "Making Backstage Controller own runtime objects. "+
"If 'true' - all runtime objects created by Controller will be syncing with desired state configured by Controller")

opts := zap.Options{
Development: true,
Expand Down Expand Up @@ -135,7 +132,6 @@ func main() {
if err = (&controller.BackstageReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
OwnsRuntime: ownRuntime,
IsOpenShift: isOpenShift,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Backstage")
Expand All @@ -153,7 +149,6 @@ func main() {
}

setupLog.Info("starting manager with parameters: ",
"own-runtime", ownRuntime,
"env.LOCALBIN", os.Getenv("LOCALBIN"),
"isOpenShift", isOpenShift,
)
Expand Down
5 changes: 2 additions & 3 deletions integration_tests/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,8 @@ func NewTestBackstageReconciler(namespace string) *TestBackstageReconciler {
}

return &TestBackstageReconciler{rec: controller.BackstageReconciler{
Client: k8sClient,
Scheme: sch,
OwnsRuntime: true,
Client: k8sClient,
Scheme: sch,
// let's set it explicitly to avoid misunderstanding
IsOpenShift: isOpenshift,
}, namespace: namespace}
Expand Down
5 changes: 1 addition & 4 deletions internal/controller/backstage_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ var watchedConfigSelector = metav1.LabelSelector{
type BackstageReconciler struct {
client.Client
Scheme *runtime.Scheme
// If true, Backstage Controller always sync the state of runtime objects created
// otherwise, runtime objects can be re-configured independently
OwnsRuntime bool
// indicates if current cluster is Openshift
IsOpenShift bool
}
Expand Down Expand Up @@ -113,7 +110,7 @@ func (r *BackstageReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
}

// This creates array of model objects to be reconsiled
bsModel, err := model.InitObjects(ctx, backstage, externalConfig, r.OwnsRuntime, r.IsOpenShift, r.Scheme)
bsModel, err := model.InitObjects(ctx, backstage, externalConfig, r.IsOpenShift, r.Scheme)
if err != nil {
return ctrl.Result{}, errorAndStatus(&backstage, "failed to initialize backstage model", err)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/model/appconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestDefaultAppConfig(t *testing.T) {

testObj := createBackstageTest(bs).withDefaultConfig(true).addToDefaultConfig("app-config.yaml", "raw-app-config.yaml")

model, err := InitObjects(context.TODO(), bs, testObj.externalConfig, true, false, testObj.scheme)
model, err := InitObjects(context.TODO(), bs, testObj.externalConfig, false, testObj.scheme)

assert.NoError(t, err)
assert.True(t, len(model.RuntimeObjects) > 0)
Expand Down Expand Up @@ -93,7 +93,7 @@ func TestSpecifiedAppConfig(t *testing.T) {
testObj.externalConfig.AppConfigs = map[string]corev1.ConfigMap{appConfigTestCm.Name: appConfigTestCm, appConfigTestCm2.Name: appConfigTestCm2,
appConfigTestCm3.Name: appConfigTestCm3}
model, err := InitObjects(context.TODO(), bs, testObj.externalConfig,
true, false, testObj.scheme)
false, testObj.scheme)

assert.NoError(t, err)
assert.True(t, len(model.RuntimeObjects) > 0)
Expand Down Expand Up @@ -127,7 +127,7 @@ func TestDefaultAndSpecifiedAppConfig(t *testing.T) {
//testObj.detailedSpec.AddConfigObject(&AppConfig{ConfigMap: &cm, MountPath: "/my/path"})
testObj.externalConfig.AppConfigs[appConfigTestCm.Name] = appConfigTestCm

model, err := InitObjects(context.TODO(), bs, testObj.externalConfig, true, false, testObj.scheme)
model, err := InitObjects(context.TODO(), bs, testObj.externalConfig, false, testObj.scheme)

assert.NoError(t, err)
assert.True(t, len(model.RuntimeObjects) > 0)
Expand Down
4 changes: 2 additions & 2 deletions pkg/model/configmapenvs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestDefaultConfigMapEnvFrom(t *testing.T) {

testObj := createBackstageTest(bs).withDefaultConfig(true).addToDefaultConfig("configmap-envs.yaml", "raw-cm-envs.yaml")

model, err := InitObjects(context.TODO(), bs, testObj.externalConfig, true, false, testObj.scheme)
model, err := InitObjects(context.TODO(), bs, testObj.externalConfig, false, testObj.scheme)

assert.NoError(t, err)
assert.NotNil(t, model)
Expand Down Expand Up @@ -66,7 +66,7 @@ func TestSpecifiedConfigMapEnvs(t *testing.T) {
testObj := createBackstageTest(bs).withDefaultConfig(true)
testObj.externalConfig.ExtraEnvConfigMaps["mapName"] = corev1.ConfigMap{Data: map[string]string{"mapName": "ENV1"}}

model, err := InitObjects(context.TODO(), bs, testObj.externalConfig, true, false, testObj.scheme)
model, err := InitObjects(context.TODO(), bs, testObj.externalConfig, false, testObj.scheme)

assert.NoError(t, err)
assert.NotNil(t, model)
Expand Down
6 changes: 3 additions & 3 deletions pkg/model/configmapfiles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestDefaultConfigMapFiles(t *testing.T) {

testObj := createBackstageTest(bs).withDefaultConfig(true).addToDefaultConfig("configmap-files.yaml", "raw-cm-files.yaml")

model, err := InitObjects(context.TODO(), bs, testObj.externalConfig, true, false, testObj.scheme)
model, err := InitObjects(context.TODO(), bs, testObj.externalConfig, false, testObj.scheme)

assert.NoError(t, err)

Expand All @@ -63,7 +63,7 @@ func TestSpecifiedConfigMapFiles(t *testing.T) {
testObj.externalConfig.ExtraFileConfigMaps["cm2"] = corev1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Name: "cm2"}, Data: map[string]string{"conf2.yaml": "data"}}
testObj.externalConfig.ExtraFileConfigMaps["cm3"] = corev1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Name: "cm3"}, Data: map[string]string{"conf3.yaml": "data"}}

model, err := InitObjects(context.TODO(), bs, testObj.externalConfig, true, false, testObj.scheme)
model, err := InitObjects(context.TODO(), bs, testObj.externalConfig, false, testObj.scheme)

assert.NoError(t, err)
assert.True(t, len(model.RuntimeObjects) > 0)
Expand Down Expand Up @@ -96,7 +96,7 @@ func TestDefaultAndSpecifiedConfigMapFiles(t *testing.T) {

testObj := createBackstageTest(bs).withDefaultConfig(true).addToDefaultConfig("configmap-files.yaml", "raw-cm-files.yaml")

model, err := InitObjects(context.TODO(), bs, testObj.externalConfig, true, false, testObj.scheme)
model, err := InitObjects(context.TODO(), bs, testObj.externalConfig, false, testObj.scheme)

assert.NoError(t, err)
assert.True(t, len(model.RuntimeObjects) > 0)
Expand Down
6 changes: 3 additions & 3 deletions pkg/model/db-secret_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestEmptyDbSecret(t *testing.T) {
// expected generatePassword = false (default db-secret defined) will come from preprocess
testObj := createBackstageTest(bs).withDefaultConfig(true).withLocalDb().addToDefaultConfig("db-secret.yaml", "db-empty-secret.yaml")

model, err := InitObjects(context.TODO(), bs, testObj.externalConfig, true, false, testObj.scheme)
model, err := InitObjects(context.TODO(), bs, testObj.externalConfig, false, testObj.scheme)

assert.NoError(t, err)
assert.NotNil(t, model.LocalDbSecret)
Expand All @@ -52,7 +52,7 @@ func TestDefaultWithGeneratedSecrets(t *testing.T) {
// expected generatePassword = true (no db-secret defined) will come from preprocess
testObj := createBackstageTest(bs).withDefaultConfig(true).withLocalDb().addToDefaultConfig("db-secret.yaml", "db-generated-secret.yaml")

model, err := InitObjects(context.TODO(), bs, testObj.externalConfig, true, false, testObj.scheme)
model, err := InitObjects(context.TODO(), bs, testObj.externalConfig, false, testObj.scheme)

assert.NoError(t, err)
assert.Equal(t, fmt.Sprintf("backstage-psql-secret-%s", bs.Name), model.LocalDbSecret.secret.Name)
Expand All @@ -73,7 +73,7 @@ func TestSpecifiedSecret(t *testing.T) {
// expected generatePassword = false (db-secret defined in the spec) will come from preprocess
testObj := createBackstageTest(bs).withDefaultConfig(true).withLocalDb().addToDefaultConfig("db-secret.yaml", "db-generated-secret.yaml")

model, err := InitObjects(context.TODO(), bs, testObj.externalConfig, true, false, testObj.scheme)
model, err := InitObjects(context.TODO(), bs, testObj.externalConfig, false, testObj.scheme)

assert.NoError(t, err)
assert.Nil(t, model.LocalDbSecret)
Expand Down
10 changes: 5 additions & 5 deletions pkg/model/db-statefulset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestDefault(t *testing.T) {
bs := *dbStatefulSetBackstage.DeepCopy()
testObj := createBackstageTest(bs).withDefaultConfig(true)

model, err := InitObjects(context.TODO(), bs, testObj.externalConfig, true, false, testObj.scheme)
model, err := InitObjects(context.TODO(), bs, testObj.externalConfig, false, testObj.scheme)
assert.NoError(t, err)

assert.Equal(t, model.LocalDbService.service.Name, model.localDbStatefulSet.statefulSet.Spec.ServiceName)
Expand All @@ -50,7 +50,7 @@ func TestOverrideDbImage(t *testing.T) {

_ = os.Setenv(LocalDbImageEnvVar, "dummy")

model, err := InitObjects(context.TODO(), bs, testObj.externalConfig, true, false, testObj.scheme)
model, err := InitObjects(context.TODO(), bs, testObj.externalConfig, false, testObj.scheme)
assert.NoError(t, err)

assert.Equal(t, "dummy", model.localDbStatefulSet.statefulSet.Spec.Template.Spec.Containers[0].Image)
Expand All @@ -62,7 +62,7 @@ func TestImagePullSecretSpec(t *testing.T) {
bs.Spec.Application.ImagePullSecrets = []string{"my-secret1", "my-secret2"}

testObj := createBackstageTest(bs).withDefaultConfig(true)
model, err := InitObjects(context.TODO(), bs, testObj.externalConfig, true, false, testObj.scheme)
model, err := InitObjects(context.TODO(), bs, testObj.externalConfig, false, testObj.scheme)
assert.NoError(t, err)

assert.Equal(t, 2, len(model.localDbStatefulSet.statefulSet.Spec.Template.Spec.ImagePullSecrets))
Expand All @@ -74,7 +74,7 @@ func TestImagePullSecretSpec(t *testing.T) {
testObj = createBackstageTest(bs).withDefaultConfig(true).
addToDefaultConfig("db-statefulset.yaml", "ips-db-statefulset.yaml")

model, err = InitObjects(context.TODO(), bs, testObj.externalConfig, true, true, testObj.scheme)
model, err = InitObjects(context.TODO(), bs, testObj.externalConfig, true, testObj.scheme)
if assert.NoError(t, err) {
// if imagepullsecrets not defined - default used
assert.Equal(t, 2, len(model.localDbStatefulSet.statefulSet.Spec.Template.Spec.ImagePullSecrets))
Expand All @@ -89,7 +89,7 @@ func TestImagePullSecretSpec(t *testing.T) {
testObj = createBackstageTest(bs).withDefaultConfig(true).
addToDefaultConfig("db-statefulset.yaml", "ips-db-statefulset.yaml")

model, err = InitObjects(context.TODO(), bs, testObj.externalConfig, true, true, testObj.scheme)
model, err = InitObjects(context.TODO(), bs, testObj.externalConfig, true, testObj.scheme)
if assert.NoError(t, err) {
assert.Equal(t, 0, len(model.localDbStatefulSet.statefulSet.Spec.Template.Spec.ImagePullSecrets))
}
Expand Down
16 changes: 8 additions & 8 deletions pkg/model/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestSpecs(t *testing.T) {
testObj := createBackstageTest(bs).withDefaultConfig(true).
addToDefaultConfig("deployment.yaml", "janus-deployment.yaml")

model, err := InitObjects(context.TODO(), bs, testObj.externalConfig, true, true, testObj.scheme)
model, err := InitObjects(context.TODO(), bs, testObj.externalConfig, true, testObj.scheme)
assert.NoError(t, err)

assert.Equal(t, "my-image:1.0.0", model.backstageDeployment.container().Image)
Expand All @@ -57,7 +57,7 @@ func TestOverrideBackstageImage(t *testing.T) {

t.Setenv(BackstageImageEnvVar, "dummy")

model, err := InitObjects(context.TODO(), bs, testObj.externalConfig, true, false, testObj.scheme)
model, err := InitObjects(context.TODO(), bs, testObj.externalConfig, false, testObj.scheme)
assert.NoError(t, err)

assert.Equal(t, 2, len(model.backstageDeployment.podSpec().Containers))
Expand All @@ -73,7 +73,7 @@ func TestSpecImagePullSecrets(t *testing.T) {
testObj := createBackstageTest(bs).withDefaultConfig(true).
addToDefaultConfig("deployment.yaml", "ips-deployment.yaml")

model, err := InitObjects(context.TODO(), bs, testObj.externalConfig, true, true, testObj.scheme)
model, err := InitObjects(context.TODO(), bs, testObj.externalConfig, true, testObj.scheme)
assert.NoError(t, err)

// if imagepullsecrets not defined - default used
Expand All @@ -85,7 +85,7 @@ func TestSpecImagePullSecrets(t *testing.T) {
testObj = createBackstageTest(bs).withDefaultConfig(true).
addToDefaultConfig("deployment.yaml", "ips-deployment.yaml")

model, err = InitObjects(context.TODO(), bs, testObj.externalConfig, true, true, testObj.scheme)
model, err = InitObjects(context.TODO(), bs, testObj.externalConfig, true, testObj.scheme)
assert.NoError(t, err)

// if explicitly set empty slice - they are empty
Expand Down Expand Up @@ -129,7 +129,7 @@ spec:
testObj := createBackstageTest(bs).withDefaultConfig(true).
addToDefaultConfig("deployment.yaml", "janus-deployment.yaml")

model, err := InitObjects(context.TODO(), bs, testObj.externalConfig, true, true, testObj.scheme)
model, err := InitObjects(context.TODO(), bs, testObj.externalConfig, true, testObj.scheme)
assert.NoError(t, err)

// label added
Expand Down Expand Up @@ -173,12 +173,12 @@ spec:

testObj := createBackstageTest(bs).withDefaultConfig(true)

model, err := InitObjects(context.TODO(), bsv1.Backstage{}, testObj.externalConfig, true, true, testObj.scheme)
model, err := InitObjects(context.TODO(), bsv1.Backstage{}, testObj.externalConfig, true, testObj.scheme)
assert.NoError(t, err)
// make sure env var works
assert.Equal(t, "envvar-image", model.backstageDeployment.container().Image)

model, err = InitObjects(context.TODO(), bs, testObj.externalConfig, true, true, testObj.scheme)
model, err = InitObjects(context.TODO(), bs, testObj.externalConfig, true, testObj.scheme)
assert.NoError(t, err)
// make sure image defined in CR overrides
assert.Equal(t, "cr-image", model.backstageDeployment.container().Image)
Expand All @@ -205,7 +205,7 @@ spec:
testObj := createBackstageTest(bs).withDefaultConfig(true).
addToDefaultConfig("deployment.yaml", "janus-deployment.yaml")

model, err := InitObjects(context.TODO(), bs, testObj.externalConfig, true, true, testObj.scheme)
model, err := InitObjects(context.TODO(), bs, testObj.externalConfig, true, testObj.scheme)
assert.NoError(t, err)

assert.Equal(t, "backstage-backend", model.backstageDeployment.container().Name)
Expand Down
12 changes: 6 additions & 6 deletions pkg/model/dynamic-plugins_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestDynamicPluginsValidationFailed(t *testing.T) {
testObj := createBackstageTest(*bs).withDefaultConfig(true).
addToDefaultConfig("dynamic-plugins.yaml", "raw-dynamic-plugins.yaml")

_, err := InitObjects(context.TODO(), *bs, testObj.externalConfig, true, false, testObj.scheme)
_, err := InitObjects(context.TODO(), *bs, testObj.externalConfig, false, testObj.scheme)

//"failed object validation, reason: failed to find initContainer named install-dynamic-plugins")
assert.Error(t, err)
Expand All @@ -57,7 +57,7 @@ func TestDynamicPluginsInvalidKeyName(t *testing.T) {
Data: map[string]string{"WrongKeyName.yml": "tt"},
}

_, err := InitObjects(context.TODO(), *bs, testObj.externalConfig, true, false, testObj.scheme)
_, err := InitObjects(context.TODO(), *bs, testObj.externalConfig, false, testObj.scheme)

assert.Error(t, err)
assert.Contains(t, err.Error(), "expects exactly one key named 'dynamic-plugins.yaml'")
Expand All @@ -73,7 +73,7 @@ func TestDefaultDynamicPlugins(t *testing.T) {
addToDefaultConfig("dynamic-plugins.yaml", "raw-dynamic-plugins.yaml").
addToDefaultConfig("deployment.yaml", "janus-deployment.yaml")

model, err := InitObjects(context.TODO(), *bs, testObj.externalConfig, true, false, testObj.scheme)
model, err := InitObjects(context.TODO(), *bs, testObj.externalConfig, false, testObj.scheme)

assert.NoError(t, err)
assert.NotNil(t, model.backstageDeployment)
Expand Down Expand Up @@ -107,7 +107,7 @@ func TestDefaultAndSpecifiedDynamicPlugins(t *testing.T) {
Data: map[string]string{DynamicPluginsFile: "tt"},
}

model, err := InitObjects(context.TODO(), *bs, testObj.externalConfig, true, false, testObj.scheme)
model, err := InitObjects(context.TODO(), *bs, testObj.externalConfig, false, testObj.scheme)

assert.NoError(t, err)
assert.NotNil(t, model)
Expand All @@ -130,7 +130,7 @@ func TestDynamicPluginsFailOnArbitraryDepl(t *testing.T) {
testObj := createBackstageTest(*bs).withDefaultConfig(true).
addToDefaultConfig("dynamic-plugins.yaml", "raw-dynamic-plugins.yaml")

_, err := InitObjects(context.TODO(), *bs, testObj.externalConfig, true, false, testObj.scheme)
_, err := InitObjects(context.TODO(), *bs, testObj.externalConfig, false, testObj.scheme)

assert.Error(t, err)
}
Expand All @@ -142,7 +142,7 @@ func TestNotConfiguredDPsNotInTheModel(t *testing.T) {

testObj := createBackstageTest(*bs).withDefaultConfig(true)

m, err := InitObjects(context.TODO(), *bs, testObj.externalConfig, true, false, testObj.scheme)
m, err := InitObjects(context.TODO(), *bs, testObj.externalConfig, false, testObj.scheme)

assert.NoError(t, err)
for _, obj := range m.RuntimeObjects {
Expand Down
4 changes: 2 additions & 2 deletions pkg/model/pvcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestDefaultPvcs(t *testing.T) {

testObj := createBackstageTest(bs).withDefaultConfig(true).addToDefaultConfig("pvcs.yaml", "multi-pvc.yaml")

model, err := InitObjects(context.TODO(), bs, testObj.externalConfig, true, true, testObj.scheme)
model, err := InitObjects(context.TODO(), bs, testObj.externalConfig, true, testObj.scheme)
assert.NoError(t, err)
assert.NotNil(t, model)

Expand Down Expand Up @@ -104,7 +104,7 @@ func TestSpecifiedPvcs(t *testing.T) {

testObj.externalConfig.ExtraPvcs = map[string]corev1.PersistentVolumeClaim{"my-pvc1": pvc1, "my-pvc2": pvc2}

model, err := InitObjects(context.TODO(), bs, testObj.externalConfig, true, true, testObj.scheme)
model, err := InitObjects(context.TODO(), bs, testObj.externalConfig, true, testObj.scheme)
assert.NoError(t, err)
assert.NotNil(t, model)
d := model.backstageDeployment
Expand Down
Loading

0 comments on commit bac4fc5

Please sign in to comment.