Skip to content

Commit

Permalink
VS controller little refactor (Kuadrant#91)
Browse files Browse the repository at this point in the history
* vs controller: little refactor

* update go.mod
  • Loading branch information
eguzki authored Feb 21, 2022
1 parent e76ed1d commit 8317588
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 236 deletions.
23 changes: 6 additions & 17 deletions controllers/apim/virtualservice_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"

ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"
Expand Down Expand Up @@ -55,22 +54,12 @@ func (r *VirtualServiceReconciler) Reconcile(eventCtx context.Context, req ctrl.
if !present {
for _, gateway := range virtualService.Spec.Gateways {
gwKey := common.NamespacedNameToObjectKey(gateway, virtualService.Namespace)
authObjKey := types.NamespacedName{
Name: getAuthPolicyName(gwKey.Name, virtualService.Name),
Namespace: gwKey.Namespace,
}

authPolicy := istiosecurityv1beta1.AuthorizationPolicy{}
if err := r.Client().Get(context.Background(), authObjKey, &authPolicy); err != nil {
// no annotation but authpolicy exist means annotation was removed.
if !apierrors.IsNotFound(err) {
logger.Error(err, "failed to check AuthorizationPolicy existence")
}
return ctrl.Result{}, nil // this virtualservice is not protected.
}

// Orphan AuthorizationPolicy exists
if err := r.Client().Delete(context.Background(), &authPolicy); err != nil {
authPolicy := &istiosecurityv1beta1.AuthorizationPolicy{}
authPolicy.SetName(getAuthPolicyName(gwKey.Name, virtualService.Name))
authPolicy.SetNamespace(gwKey.Namespace)
common.TagObjectToDelete(authPolicy)
err := r.ReconcileResource(ctx, &istiosecurityv1beta1.AuthorizationPolicy{}, authPolicy, nil)
if err != nil {
logger.Error(err, "failed to delete orphan authorizationpolicy")
return ctrl.Result{}, err
}
Expand Down
7 changes: 0 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@ go 1.16

require (
github.com/Azure/go-autorest/autorest v0.11.19 // indirect
github.com/getkin/kin-openapi v0.63.0
github.com/go-logr/logr v0.4.0
github.com/gogo/protobuf v1.3.2
github.com/google/go-cmp v0.5.5
github.com/google/uuid v1.1.2
github.com/jarcoal/httpmock v1.0.8
github.com/kuadrant/authorino v0.7.0
github.com/kuadrant/limitador-operator v0.2.0
github.com/onsi/ginkgo v1.16.4
github.com/onsi/gomega v1.15.0
Expand All @@ -19,10 +14,8 @@ require (
istio.io/api v0.0.0-20210219142745-68975986cccb
istio.io/client-go v1.9.0
k8s.io/api v0.22.1
k8s.io/apiextensions-apiserver v0.22.1
k8s.io/apimachinery v0.22.1
k8s.io/client-go v0.22.1
k8s.io/klog/v2 v2.9.0
sigs.k8s.io/controller-runtime v0.10.0
sigs.k8s.io/gateway-api v0.3.0
)
Loading

0 comments on commit 8317588

Please sign in to comment.