Skip to content

Commit

Permalink
refactor: replace code with features now available in c-r
Browse files Browse the repository at this point in the history
  • Loading branch information
erikgb committed Jan 9, 2023
1 parent c662723 commit 4a3f127
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 53 deletions.
18 changes: 0 additions & 18 deletions controllers/predicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,21 +106,3 @@ var jobIsFinished = predicate.NewPredicateFuncs(func(object client.Object) bool
var cisVulnerabilityOverflow = predicate.NewPredicateFuncs(func(object client.Object) bool {
return object.(*stasv1alpha1.ContainerImageScan).HasVulnerabilityOverflow()
})

// TODO: Replace with new func added to c-r in https://github.com/kubernetes-sigs/controller-runtime/pull/2031
func notPredicate(p predicate.Predicate) predicate.Predicate {
return predicate.Funcs{
CreateFunc: func(event event.CreateEvent) bool {
return !p.Create(event)
},
DeleteFunc: func(event event.DeleteEvent) bool {
return !p.Delete(event)
},
UpdateFunc: func(event event.UpdateEvent) bool {
return !p.Update(event)
},
GenericFunc: func(event event.GenericEvent) bool {
return !p.Generic(event)
},
}
}
4 changes: 2 additions & 2 deletions controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ import (
"k8s.io/client-go/rest"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/cluster"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/envtest"
"sigs.k8s.io/controller-runtime/pkg/envtest/komega"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"

stasv1alpha1 "github.com/statnett/image-scanner-operator/api/v1alpha1"
"github.com/statnett/image-scanner-operator/internal/cluster"
"github.com/statnett/image-scanner-operator/internal/pod"
"github.com/statnett/image-scanner-operator/pkg/operator"
//+kubebuilder:scaffold:imports
Expand Down Expand Up @@ -90,7 +90,7 @@ var _ = BeforeSuite(func() {
}

k8sManager, err := ctrl.NewManager(cfg, ctrl.Options{
NewClient: cluster.NewCachingClient,
NewClient: cluster.ClientBuilderWithOptions(cluster.ClientOptions{CacheUnstructured: true}),
Scheme: scheme.Scheme,
})
Expect(err).NotTo(HaveOccurred())
Expand Down
4 changes: 2 additions & 2 deletions controllers/workload_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ func (r *PodReconciler) SetupWithManager(mgr ctrl.Manager) error {
ignoreDeletionPredicate(),
)).
WithEventFilter(predicate.And(
notPredicate(systemNamespace),
notPredicate(managedByImageScanner),
predicate.Not(systemNamespace),
predicate.Not(managedByImageScanner),
)).
Watches(&source.Kind{Type: &stasv1alpha1.ContainerImageScan{}},
&handler.EnqueueRequestForOwner{OwnerType: &corev1.Pod{}},
Expand Down
29 changes: 0 additions & 29 deletions internal/cluster/cache_unstructured.go

This file was deleted.

4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import (
_ "k8s.io/client-go/plugin/pkg/client/auth"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/cluster"
"sigs.k8s.io/controller-runtime/pkg/healthz"

stasv1alpha1 "github.com/statnett/image-scanner-operator/api/v1alpha1"
"github.com/statnett/image-scanner-operator/controllers"
"github.com/statnett/image-scanner-operator/internal/cluster"
"github.com/statnett/image-scanner-operator/internal/metrics"
"github.com/statnett/image-scanner-operator/internal/pod"
"github.com/statnett/image-scanner-operator/internal/resources"
Expand Down Expand Up @@ -96,7 +96,7 @@ func main() {
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))

options := ctrl.Options{
NewClient: cluster.NewCachingClient,
NewClient: cluster.ClientBuilderWithOptions(cluster.ClientOptions{CacheUnstructured: true}),
Scheme: scheme,
MetricsBindAddress: metricsAddr,
Port: 9443,
Expand Down

0 comments on commit 4a3f127

Please sign in to comment.