From 481d8576826be603a0e0a20ac0639e511e9cbe4a Mon Sep 17 00:00:00 2001 From: bdumpp <144795224+bdumpp@users.noreply.github.com> Date: Tue, 5 Dec 2023 13:16:16 +0100 Subject: [PATCH] :boom: removed code from pr #70 (#222) --- .../controller/styra/system_controller.go | 59 +------------- internal/webhook/mocks/client.go | 8 ++ pkg/styra/mocks/client_interface.go | 76 +++++++++++++++++++ 3 files changed, 86 insertions(+), 57 deletions(-) diff --git a/internal/controller/styra/system_controller.go b/internal/controller/styra/system_controller.go index 4bcc98e..82a9c2d 100644 --- a/internal/controller/styra/system_controller.go +++ b/internal/controller/styra/system_controller.go @@ -827,18 +827,6 @@ func (r *SystemReconciler) reconcileOPAToken( update := false - // backwards compatibility: StyraSystem - if isControlledByStyraSystem(&s) { - log.Info("Secret owned by StyraSystem. Taking ownership.") - s.OwnerReferences = nil - if err := controllerutil.SetControllerReference(system, &s, r.Scheme); err != nil { - return ctrl.Result{}, false, ctrlerr.Wrap(err, "Could not set owner reference on Secret"). - WithEvent("ErrorOwnerRefOPATokenSecret"). - WithSystemCondition(v1beta1.ConditionTypeOPATokenUpdated) - } - update = true - } - if !metav1.IsControlledBy(&s, system) { return ctrl.Result{}, false, ctrlerr.New("Existing secret is not owned by controller. Skipping update"). WithEvent("ErrorSecretNotOwnedByController"). @@ -865,16 +853,6 @@ func (r *SystemReconciler) reconcileOPAToken( return ctrl.Result{}, update, nil } -// backwards compatibility: StyraSystem -func isControlledByStyraSystem(o metav1.Object) bool { - for _, ref := range o.GetOwnerReferences() { - if ref.Kind == "StyraSystem" { - return true - } - } - return false -} - func (r *SystemReconciler) reconcileOPAConfigMap( ctx context.Context, log logr.Logger, @@ -933,18 +911,6 @@ func (r *SystemReconciler) reconcileOPAConfigMap( update := false - // backwards compatibility: StyraSystem - if isControlledByStyraSystem(&cm) { - log.Info("ConfigMap owned by StyraSystem. Taking ownership.") - cm.OwnerReferences = nil - if err := controllerutil.SetControllerReference(system, &cm, r.Scheme); err != nil { - return ctrl.Result{}, false, ctrlerr.Wrap(err, "Could not set owner reference on Secret"). - WithEvent("ErrorOwnerRefOPATokenSecret"). - WithSystemCondition(v1beta1.ConditionTypeOPATokenUpdated) - } - update = true - } - if !metav1.IsControlledBy(&cm, system) { return ctrl.Result{}, false, ctrlerr.New("ConfigMap already exists and is not owned by controller"). WithEvent("ErrorConfigMapNotOwnedByController"). @@ -1025,18 +991,6 @@ func (r *SystemReconciler) reconcileSLPConfigMap( update := false - // backwards compatibility: StyraSystem - if isControlledByStyraSystem(&cm) { - log.Info("ConfigMap owned by StyraSystem. Taking ownership.") - cm.OwnerReferences = nil - if err := controllerutil.SetControllerReference(system, &cm, r.Scheme); err != nil { - return ctrl.Result{}, false, ctrlerr.Wrap(err, "Could not set owner reference on Secret"). - WithEvent("ErrorOwnerRefOPATokenSecret"). - WithSystemCondition(v1beta1.ConditionTypeOPATokenUpdated) - } - update = true - } - if !metav1.IsControlledBy(&cm, system) { return ctrl.Result{}, false, ctrlerr.New("ConfigMap already exists and is not owned by controller"). WithEvent("ErrorFetchSLPConfigMap"). @@ -1294,17 +1248,8 @@ func (r *SystemReconciler) findSecretOwners(ctx context.Context, secret client.O } func ownerIsSystem(owner metav1.OwnerReference) bool { - if owner.APIVersion != v1beta1.GroupVersion.String() && - // backwards compatibility: StyraSystem - owner.APIVersion != "styra.bankdata.dk/v1alpha1" { - return false - } - if owner.Kind != "System" && - // backwards compatibility: StyraSystem - owner.Kind != "StyraSystem" { - return false - } - return true + return owner.APIVersion == v1beta1.GroupVersion.String() && + owner.Kind == "System" } // findSystemsForConfigMap detects if modified configmap is the configmap containing opa/slp config. diff --git a/internal/webhook/mocks/client.go b/internal/webhook/mocks/client.go index 963f1c9..858d76c 100644 --- a/internal/webhook/mocks/client.go +++ b/internal/webhook/mocks/client.go @@ -18,6 +18,10 @@ type Client struct { func (_m *Client) LibraryDatasourceChanged(_a0 context.Context, _a1 logr.Logger, _a2 string) error { ret := _m.Called(_a0, _a1, _a2) + if len(ret) == 0 { + panic("no return value specified for LibraryDatasourceChanged") + } + var r0 error if rf, ok := ret.Get(0).(func(context.Context, logr.Logger, string) error); ok { r0 = rf(_a0, _a1, _a2) @@ -32,6 +36,10 @@ func (_m *Client) LibraryDatasourceChanged(_a0 context.Context, _a1 logr.Logger, func (_m *Client) SystemDatasourceChanged(_a0 context.Context, _a1 logr.Logger, _a2 string, _a3 string) error { ret := _m.Called(_a0, _a1, _a2, _a3) + if len(ret) == 0 { + panic("no return value specified for SystemDatasourceChanged") + } + var r0 error if rf, ok := ret.Get(0).(func(context.Context, logr.Logger, string, string) error); ok { r0 = rf(_a0, _a1, _a2, _a3) diff --git a/pkg/styra/mocks/client_interface.go b/pkg/styra/mocks/client_interface.go index 3343166..5102b2f 100644 --- a/pkg/styra/mocks/client_interface.go +++ b/pkg/styra/mocks/client_interface.go @@ -18,6 +18,10 @@ type ClientInterface struct { func (_m *ClientInterface) CreateInvitation(ctx context.Context, email bool, name string) (*styra.CreateInvitationResponse, error) { ret := _m.Called(ctx, email, name) + if len(ret) == 0 { + panic("no return value specified for CreateInvitation") + } + var r0 *styra.CreateInvitationResponse var r1 error if rf, ok := ret.Get(0).(func(context.Context, bool, string) (*styra.CreateInvitationResponse, error)); ok { @@ -44,6 +48,10 @@ func (_m *ClientInterface) CreateInvitation(ctx context.Context, email bool, nam func (_m *ClientInterface) CreateRoleBinding(ctx context.Context, request *styra.CreateRoleBindingRequest) (*styra.CreateRoleBindingResponse, error) { ret := _m.Called(ctx, request) + if len(ret) == 0 { + panic("no return value specified for CreateRoleBinding") + } + var r0 *styra.CreateRoleBindingResponse var r1 error if rf, ok := ret.Get(0).(func(context.Context, *styra.CreateRoleBindingRequest) (*styra.CreateRoleBindingResponse, error)); ok { @@ -70,6 +78,10 @@ func (_m *ClientInterface) CreateRoleBinding(ctx context.Context, request *styra func (_m *ClientInterface) CreateSystem(ctx context.Context, request *styra.CreateSystemRequest) (*styra.CreateSystemResponse, error) { ret := _m.Called(ctx, request) + if len(ret) == 0 { + panic("no return value specified for CreateSystem") + } + var r0 *styra.CreateSystemResponse var r1 error if rf, ok := ret.Get(0).(func(context.Context, *styra.CreateSystemRequest) (*styra.CreateSystemResponse, error)); ok { @@ -96,6 +108,10 @@ func (_m *ClientInterface) CreateSystem(ctx context.Context, request *styra.Crea func (_m *ClientInterface) CreateUpdateSecret(ctx context.Context, secretID string, request *styra.CreateUpdateSecretsRequest) (*styra.CreateUpdateSecretResponse, error) { ret := _m.Called(ctx, secretID, request) + if len(ret) == 0 { + panic("no return value specified for CreateUpdateSecret") + } + var r0 *styra.CreateUpdateSecretResponse var r1 error if rf, ok := ret.Get(0).(func(context.Context, string, *styra.CreateUpdateSecretsRequest) (*styra.CreateUpdateSecretResponse, error)); ok { @@ -122,6 +138,10 @@ func (_m *ClientInterface) CreateUpdateSecret(ctx context.Context, secretID stri func (_m *ClientInterface) DeleteDatasource(ctx context.Context, id string) (*styra.DeleteDatasourceResponse, error) { ret := _m.Called(ctx, id) + if len(ret) == 0 { + panic("no return value specified for DeleteDatasource") + } + var r0 *styra.DeleteDatasourceResponse var r1 error if rf, ok := ret.Get(0).(func(context.Context, string) (*styra.DeleteDatasourceResponse, error)); ok { @@ -148,6 +168,10 @@ func (_m *ClientInterface) DeleteDatasource(ctx context.Context, id string) (*st func (_m *ClientInterface) DeletePolicy(ctx context.Context, policyName string) (*styra.DeletePolicyResponse, error) { ret := _m.Called(ctx, policyName) + if len(ret) == 0 { + panic("no return value specified for DeletePolicy") + } + var r0 *styra.DeletePolicyResponse var r1 error if rf, ok := ret.Get(0).(func(context.Context, string) (*styra.DeletePolicyResponse, error)); ok { @@ -174,6 +198,10 @@ func (_m *ClientInterface) DeletePolicy(ctx context.Context, policyName string) func (_m *ClientInterface) DeleteRoleBindingV2(ctx context.Context, id string) (*styra.DeleteRoleBindingV2Response, error) { ret := _m.Called(ctx, id) + if len(ret) == 0 { + panic("no return value specified for DeleteRoleBindingV2") + } + var r0 *styra.DeleteRoleBindingV2Response var r1 error if rf, ok := ret.Get(0).(func(context.Context, string) (*styra.DeleteRoleBindingV2Response, error)); ok { @@ -200,6 +228,10 @@ func (_m *ClientInterface) DeleteRoleBindingV2(ctx context.Context, id string) ( func (_m *ClientInterface) DeleteSystem(ctx context.Context, id string) (*styra.DeleteSystemResponse, error) { ret := _m.Called(ctx, id) + if len(ret) == 0 { + panic("no return value specified for DeleteSystem") + } + var r0 *styra.DeleteSystemResponse var r1 error if rf, ok := ret.Get(0).(func(context.Context, string) (*styra.DeleteSystemResponse, error)); ok { @@ -226,6 +258,10 @@ func (_m *ClientInterface) DeleteSystem(ctx context.Context, id string) (*styra. func (_m *ClientInterface) GetDatasource(ctx context.Context, id string) (*styra.GetDatasourceResponse, error) { ret := _m.Called(ctx, id) + if len(ret) == 0 { + panic("no return value specified for GetDatasource") + } + var r0 *styra.GetDatasourceResponse var r1 error if rf, ok := ret.Get(0).(func(context.Context, string) (*styra.GetDatasourceResponse, error)); ok { @@ -252,6 +288,10 @@ func (_m *ClientInterface) GetDatasource(ctx context.Context, id string) (*styra func (_m *ClientInterface) GetLibrary(ctx context.Context, id string) (*styra.GetLibraryResponse, error) { ret := _m.Called(ctx, id) + if len(ret) == 0 { + panic("no return value specified for GetLibrary") + } + var r0 *styra.GetLibraryResponse var r1 error if rf, ok := ret.Get(0).(func(context.Context, string) (*styra.GetLibraryResponse, error)); ok { @@ -278,6 +318,10 @@ func (_m *ClientInterface) GetLibrary(ctx context.Context, id string) (*styra.Ge func (_m *ClientInterface) GetOPAConfig(ctx context.Context, systemID string) (styra.OPAConfig, error) { ret := _m.Called(ctx, systemID) + if len(ret) == 0 { + panic("no return value specified for GetOPAConfig") + } + var r0 styra.OPAConfig var r1 error if rf, ok := ret.Get(0).(func(context.Context, string) (styra.OPAConfig, error)); ok { @@ -302,6 +346,10 @@ func (_m *ClientInterface) GetOPAConfig(ctx context.Context, systemID string) (s func (_m *ClientInterface) GetSystem(ctx context.Context, id string) (*styra.GetSystemResponse, error) { ret := _m.Called(ctx, id) + if len(ret) == 0 { + panic("no return value specified for GetSystem") + } + var r0 *styra.GetSystemResponse var r1 error if rf, ok := ret.Get(0).(func(context.Context, string) (*styra.GetSystemResponse, error)); ok { @@ -328,6 +376,10 @@ func (_m *ClientInterface) GetSystem(ctx context.Context, id string) (*styra.Get func (_m *ClientInterface) GetUser(ctx context.Context, name string) (*styra.GetUserResponse, error) { ret := _m.Called(ctx, name) + if len(ret) == 0 { + panic("no return value specified for GetUser") + } + var r0 *styra.GetUserResponse var r1 error if rf, ok := ret.Get(0).(func(context.Context, string) (*styra.GetUserResponse, error)); ok { @@ -354,6 +406,10 @@ func (_m *ClientInterface) GetUser(ctx context.Context, name string) (*styra.Get func (_m *ClientInterface) ListRoleBindingsV2(ctx context.Context, params *styra.ListRoleBindingsV2Params) (*styra.ListRoleBindingsV2Response, error) { ret := _m.Called(ctx, params) + if len(ret) == 0 { + panic("no return value specified for ListRoleBindingsV2") + } + var r0 *styra.ListRoleBindingsV2Response var r1 error if rf, ok := ret.Get(0).(func(context.Context, *styra.ListRoleBindingsV2Params) (*styra.ListRoleBindingsV2Response, error)); ok { @@ -380,6 +436,10 @@ func (_m *ClientInterface) ListRoleBindingsV2(ctx context.Context, params *styra func (_m *ClientInterface) UpdateRoleBindingSubjects(ctx context.Context, id string, request *styra.UpdateRoleBindingSubjectsRequest) (*styra.UpdateRoleBindingSubjectsResponse, error) { ret := _m.Called(ctx, id, request) + if len(ret) == 0 { + panic("no return value specified for UpdateRoleBindingSubjects") + } + var r0 *styra.UpdateRoleBindingSubjectsResponse var r1 error if rf, ok := ret.Get(0).(func(context.Context, string, *styra.UpdateRoleBindingSubjectsRequest) (*styra.UpdateRoleBindingSubjectsResponse, error)); ok { @@ -406,6 +466,10 @@ func (_m *ClientInterface) UpdateRoleBindingSubjects(ctx context.Context, id str func (_m *ClientInterface) UpdateSystem(ctx context.Context, id string, request *styra.UpdateSystemRequest) (*styra.UpdateSystemResponse, error) { ret := _m.Called(ctx, id, request) + if len(ret) == 0 { + panic("no return value specified for UpdateSystem") + } + var r0 *styra.UpdateSystemResponse var r1 error if rf, ok := ret.Get(0).(func(context.Context, string, *styra.UpdateSystemRequest) (*styra.UpdateSystemResponse, error)); ok { @@ -432,6 +496,10 @@ func (_m *ClientInterface) UpdateSystem(ctx context.Context, id string, request func (_m *ClientInterface) UpsertDatasource(ctx context.Context, id string, request *styra.UpsertDatasourceRequest) (*styra.UpsertDatasourceResponse, error) { ret := _m.Called(ctx, id, request) + if len(ret) == 0 { + panic("no return value specified for UpsertDatasource") + } + var r0 *styra.UpsertDatasourceResponse var r1 error if rf, ok := ret.Get(0).(func(context.Context, string, *styra.UpsertDatasourceRequest) (*styra.UpsertDatasourceResponse, error)); ok { @@ -458,6 +526,10 @@ func (_m *ClientInterface) UpsertDatasource(ctx context.Context, id string, requ func (_m *ClientInterface) UpsertLibrary(ctx context.Context, id string, request *styra.UpsertLibraryRequest) (*styra.UpsertLibraryResponse, error) { ret := _m.Called(ctx, id, request) + if len(ret) == 0 { + panic("no return value specified for UpsertLibrary") + } + var r0 *styra.UpsertLibraryResponse var r1 error if rf, ok := ret.Get(0).(func(context.Context, string, *styra.UpsertLibraryRequest) (*styra.UpsertLibraryResponse, error)); ok { @@ -484,6 +556,10 @@ func (_m *ClientInterface) UpsertLibrary(ctx context.Context, id string, request func (_m *ClientInterface) VerifyGitConfiguration(ctx context.Context, request *styra.VerfiyGitConfigRequest) (*styra.VerfiyGitConfigResponse, error) { ret := _m.Called(ctx, request) + if len(ret) == 0 { + panic("no return value specified for VerifyGitConfiguration") + } + var r0 *styra.VerfiyGitConfigResponse var r1 error if rf, ok := ret.Get(0).(func(context.Context, *styra.VerfiyGitConfigRequest) (*styra.VerfiyGitConfigResponse, error)); ok {