Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace code with features now available in c-r #10

Merged
merged 1 commit into from Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 0 additions & 18 deletions controllers/predicates.go
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
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
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
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 @@ -97,7 +97,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