Skip to content

Commit

Permalink
ignore pdb selector change at reconcile
Browse files Browse the repository at this point in the history
  • Loading branch information
waynz0r committed Feb 8, 2022
1 parent 9ec8a53 commit f876760
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 4 deletions.
2 changes: 1 addition & 1 deletion controllers/meshgateway_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (r *IstioMeshGatewayReconciler) Reconcile(ctx context.Context, req ctrl.Req
MeshConfigChecksum: icp.Status.GetChecksums().GetMeshConfig(),
IstioControlPlane: icp,
GenerateExternalService: generateExternalService,
})
}, r.Log)
}, r.Log.WithName("istiomeshgateway"))
if err != nil {
return ctrl.Result{}, err
Expand Down
4 changes: 3 additions & 1 deletion internal/components/discovery/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ func TestICPDiscoveryResourceDump(t *testing.T) {
MeshNetworks: getTestMeshNetworks(),
TrustedRootCACertificatePEMs: []string{"<pem content from peer>"},
},
logr.DiscardLogger{},
testlogr.TestLogger{
T: t,
},
)

dd, err := reconciler.GetManifest(icp)
Expand Down
23 changes: 23 additions & 0 deletions internal/components/discovery/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/go-logr/logr"
admissionregistrationv1 "k8s.io/api/admissionregistration/v1"
corev1 "k8s.io/api/core/v1"
policyv1beta1 "k8s.io/api/policy/v1beta1"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand Down Expand Up @@ -108,6 +109,28 @@ func (rec *Component) ReleaseData(object runtime.Object) (*templatereconciler.Re

patchResult, err := patch.DefaultPatchMaker.Calculate(current, desired, options...)
if err != nil {
rec.logger.Error(err, "could not calculate patch result")

return false, err
}

return !patchResult.IsEmpty(), nil
},
},
{
GVK: policyv1beta1.SchemeGroupVersion.WithKind("PodDisruptionBudget"),
}: reconciler.DynamicDesiredState{
ShouldUpdateFunc: func(current, desired runtime.Object) (bool, error) {
options := []patch.CalculateOption{
patch.IgnoreStatusFields(),
reconciler.IgnoreManagedFields(),
patch.IgnorePDBSelector(),
}

patchResult, err := patch.DefaultPatchMaker.Calculate(current, desired, options...)
if err != nil {
rec.logger.Error(err, "could not calculate patch result")

return false, err
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"emperror.dev/errors"
"emperror.dev/errors/utils/keyval"
testlogr "github.com/go-logr/logr/testing"
"github.com/homeport/dyff/pkg/dyff"
"k8s.io/client-go/kubernetes/fake"
"sigs.k8s.io/yaml"
Expand Down Expand Up @@ -62,7 +63,9 @@ func TestIMGWResourceDump(t *testing.T) {
}

reconciler := istiomeshgateway.NewChartReconciler(
templatereconciler.NewHelmReconciler(nil, nil, nil, fake.NewSimpleClientset().Discovery(), []reconciler.NativeReconcilerOpt{
templatereconciler.NewHelmReconciler(nil, nil, testlogr.TestLogger{
T: t,
}, fake.NewSimpleClientset().Discovery(), []reconciler.NativeReconcilerOpt{
reconciler.NativeReconcilerSetControllerRef(),
}),
v1alpha1.IstioMeshGatewayProperties{
Expand All @@ -74,6 +77,9 @@ func TestIMGWResourceDump(t *testing.T) {
IstioControlPlane: icp,
GenerateExternalService: true,
},
testlogr.TestLogger{
T: t,
},
)

dd, err := reconciler.GetManifest(imgw)
Expand Down
30 changes: 29 additions & 1 deletion internal/components/istiomeshgateway/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@ import (
"net/http"

"emperror.dev/errors"
"github.com/go-logr/logr"
policyv1beta1 "k8s.io/api/policy/v1beta1"
"k8s.io/apimachinery/pkg/runtime"

"github.com/banzaicloud/istio-operator/api/v2/v1alpha1"
"github.com/banzaicloud/istio-operator/v2/internal/assets"
"github.com/banzaicloud/istio-operator/v2/internal/components"
"github.com/banzaicloud/istio-operator/v2/internal/util"
"github.com/banzaicloud/k8s-objectmatcher/patch"
"github.com/banzaicloud/operator-tools/pkg/helm"
"github.com/banzaicloud/operator-tools/pkg/helm/templatereconciler"
"github.com/banzaicloud/operator-tools/pkg/reconciler"
)

const (
Expand All @@ -42,13 +46,15 @@ var _ components.MinimalComponent = &Component{}

type Component struct {
properties v1alpha1.IstioMeshGatewayProperties
logger logr.Logger
}

func NewChartReconciler(helmReconciler *components.HelmReconciler, properties v1alpha1.IstioMeshGatewayProperties) components.ComponentReconciler {
func NewChartReconciler(helmReconciler *components.HelmReconciler, properties v1alpha1.IstioMeshGatewayProperties, logger logr.Logger) components.ComponentReconciler {
return &components.Base{
HelmReconciler: helmReconciler,
Component: &Component{
properties: properties,
logger: logger,
},
}
}
Expand Down Expand Up @@ -84,6 +90,28 @@ func (rec *Component) ReleaseData(object runtime.Object) (*templatereconciler.Re
ChartName: chartName,
ReleaseName: releaseName,
Layers: overlays,
DesiredStateOverrides: map[reconciler.ObjectKeyWithGVK]reconciler.DesiredState{
{
GVK: policyv1beta1.SchemeGroupVersion.WithKind("PodDisruptionBudget"),
}: reconciler.DynamicDesiredState{
ShouldUpdateFunc: func(current, desired runtime.Object) (bool, error) {
options := []patch.CalculateOption{
patch.IgnoreStatusFields(),
reconciler.IgnoreManagedFields(),
patch.IgnorePDBSelector(),
}

patchResult, err := patch.DefaultPatchMaker.Calculate(current, desired, options...)
if err != nil {
rec.logger.Error(err, "could not calculate patch result")

return false, err
}

return !patchResult.IsEmpty(), nil
},
},
},
}, nil
}

Expand Down
1 change: 1 addition & 0 deletions internal/util/predicate.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func (p ObjectChangePredicate) Update(e event.UpdateEvent) bool {
if p.Logger != nil {
p.Logger.Error(errors.WithStack(err), "could not calculate patch result")
}

return true
} else if patchResult.IsEmpty() {
return false
Expand Down

0 comments on commit f876760

Please sign in to comment.