Skip to content

Commit

Permalink
Fix Istio CRD name and add log message
Browse files Browse the repository at this point in the history
  • Loading branch information
NetanelBollag committed May 3, 2023
1 parent 4b2afa4 commit a7a7848
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/operator/controllers/intents_reconcilers/istio_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,13 @@ func NewIstioPolicyReconciler(
}

func (r *IstioPolicyReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
isIstioInstalled, err := istiopolicy.IsIstioInstalled(ctx, r.Client)
isIstioInstalled, err := istiopolicy.IsIstioAuthorizationPoliciesInstalled(ctx, r.Client)
if err != nil {
return ctrl.Result{}, err
}

if !isIstioInstalled {
logrus.Warning("authorization policies CRD is not installed, Istio policy creation skipped")
return ctrl.Result{}, nil
}

Expand Down
9 changes: 5 additions & 4 deletions src/operator/controllers/istiopolicy/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
k8serrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
"strings"
)

const (
IstioCRDName = "authorizationpolicies.security.istio.io"
IstioProxyContainerName = "istio-proxy"
)

Expand All @@ -25,12 +25,13 @@ func IsPodPartOfIstioMesh(pod corev1.Pod) bool {
return false
}

func IsIstioInstalled(ctx context.Context, client client.Client) (bool, error) {
gvks, _, err := client.Scheme().ObjectKinds(&v1beta1.AuthorizationPolicy{})
func IsIstioAuthorizationPoliciesInstalled(ctx context.Context, client client.Client) (bool, error) {
groupVersionKinds, _, err := client.Scheme().ObjectKinds(&v1beta1.AuthorizationPolicy{})
if err != nil {
return false, err
}
istioCRDName := fmt.Sprintf("%s.%s", strings.ToLower(gvks[0].Kind), gvks[0].Group)

istioCRDName := fmt.Sprintf("authorizationpolicies.%s", groupVersionKinds[0].Group)
crd := apiextensionsv1.CustomResourceDefinition{}
err = client.Get(ctx, types.NamespacedName{Name: istioCRDName}, &crd)
if err != nil && !k8serrors.IsNotFound(err) {
Expand Down
3 changes: 2 additions & 1 deletion src/watcher/reconcilers/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,13 @@ func (p *PodWatcher) handleIstioPolicy(ctx context.Context, pod v1.Pod, serviceI
return nil
}

isIstioInstalled, err := istiopolicy.IsIstioInstalled(ctx, p.Client)
isIstioInstalled, err := istiopolicy.IsIstioAuthorizationPoliciesInstalled(ctx, p.Client)
if err != nil {
return err
}

if !isIstioInstalled {
logrus.Warning("authorization policies CRD is not installed, Istio policy creation skipped")
return nil
}

Expand Down

0 comments on commit a7a7848

Please sign in to comment.