Skip to content

Commit

Permalink
Upgrade controller-runtime to v0.7.0
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
  • Loading branch information
stefanprodan committed Dec 17, 2020
1 parent f0a3147 commit 0b722a7
Show file tree
Hide file tree
Showing 10 changed files with 360 additions and 207 deletions.
4 changes: 2 additions & 2 deletions api/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ go 1.15

require (
github.com/fluxcd/pkg/apis/meta v0.5.0
github.com/fluxcd/pkg/runtime v0.4.0
github.com/fluxcd/pkg/runtime v0.5.1-0.20201217125143-9e1fe564d778
k8s.io/api v0.19.4
k8s.io/apimachinery v0.19.4
sigs.k8s.io/controller-runtime v0.6.4
sigs.k8s.io/controller-runtime v0.7.0
)
150 changes: 92 additions & 58 deletions api/go.sum

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions api/v1beta1/kustomization_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,9 @@ func (in *Kustomization) GetStatusConditions() *[]metav1.Condition {
}

const (
// SourceIndexKey is the key used for indexing kustomizations
// GitRepositoryIndexKey is the key used for indexing kustomizations
// based on their Git sources.
SourceIndexKey string = ".metadata.source"
GitRepositoryIndexKey string = ".metadata.git"
// BucketIndexKey is the key used for indexing kustomizations
// based on their S3 sources.
BucketIndexKey string = ".metadata.bucket"
Expand Down
209 changes: 99 additions & 110 deletions controllers/kustomization_controller.go

Large diffs are not rendered by default.

10 changes: 1 addition & 9 deletions controllers/source_predicate.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type SourceRevisionChangePredicate struct {
}

func (SourceRevisionChangePredicate) Update(e event.UpdateEvent) bool {
if e.MetaOld == nil || e.MetaNew == nil {
if e.ObjectOld == nil || e.ObjectNew == nil {
return false
}

Expand All @@ -53,11 +53,3 @@ func (SourceRevisionChangePredicate) Update(e event.UpdateEvent) bool {

return false
}

func (SourceRevisionChangePredicate) Create(e event.CreateEvent) bool {
return false
}

func (SourceRevisionChangePredicate) Delete(e event.DeleteEvent) bool {
return false
}
5 changes: 3 additions & 2 deletions controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ func TestAPIs(t *testing.T) {
}

var _ = BeforeSuite(func(done Done) {
logf.SetLogger(zap.LoggerTo(GinkgoWriter, true))
logf.SetLogger(
zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true)),
)

By("bootstrapping test environment")
t := true
Expand Down Expand Up @@ -90,7 +92,6 @@ var _ = BeforeSuite(func(done Done) {

err = (&KustomizationReconciler{
Client: k8sManager.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("Kustomization"),
Scheme: scheme.Scheme,
EventRecorder: k8sManager.GetEventRecorderFor("kustomize-controller"),
ExternalEventRecorder: nil,
Expand Down
14 changes: 13 additions & 1 deletion controllers/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ limitations under the License.

package controllers

import "strings"
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
"strings"
)

// parseApplyOutput extracts the objects and the action
// performed by kubectl e.g.:
Expand Down Expand Up @@ -69,3 +73,11 @@ func containsString(slice []string, s string) bool {
}
return false
}

// ObjectKey returns client.ObjectKey for the object.
func ObjectKey(object metav1.Object) client.ObjectKey {
return client.ObjectKey{
Namespace: object.GetNamespace(),
Name: object.GetName(),
}
}
15 changes: 6 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ require (
github.com/cyphar/filepath-securejoin v0.2.2
github.com/fluxcd/kustomize-controller/api v0.5.2
github.com/fluxcd/pkg/apis/meta v0.5.0
github.com/fluxcd/pkg/runtime v0.4.0
github.com/fluxcd/pkg/runtime v0.5.1-0.20201217125143-9e1fe564d778
github.com/fluxcd/pkg/testserver v0.0.2
github.com/fluxcd/pkg/untar v0.0.5
github.com/fluxcd/source-controller/api v0.5.5
github.com/go-logr/logr v0.2.1
github.com/go-logr/logr v0.3.0
github.com/howeyc/gopass v0.0.0-20170109162249-bf9dde6d0d2c
github.com/onsi/ginkgo v1.12.1
github.com/onsi/gomega v1.10.1
github.com/onsi/ginkgo v1.14.1
github.com/onsi/gomega v1.10.2
github.com/spf13/pflag v1.0.5
go.mozilla.org/gopgagent v0.0.0-20170926210634-4d7ea76ff71a
go.mozilla.org/sops/v3 v3.6.1
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
Expand All @@ -26,11 +27,7 @@ require (
k8s.io/cli-runtime v0.19.4 // indirect
k8s.io/client-go v0.19.4
sigs.k8s.io/cli-utils v0.19.2
sigs.k8s.io/controller-runtime v0.6.4
sigs.k8s.io/controller-runtime v0.7.0
sigs.k8s.io/kustomize/api v0.7.0
sigs.k8s.io/yaml v1.2.0
)

// controller-runtime v0.6.4 bug:
// v1.ListOptions is not suitable for converting to \"helm.toolkit.fluxcd.io/v2beta1\" in scheme \"pkg/runtime/scheme.go:101
replace sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.6.3
137 changes: 131 additions & 6 deletions go.sum

Large diffs are not rendered by default.

19 changes: 11 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ limitations under the License.
package main

import (
"flag"
goflag "flag"
"os"
"time"

flag "github.com/spf13/pflag"
"k8s.io/apimachinery/pkg/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
Expand Down Expand Up @@ -60,11 +61,9 @@ func main() {
enableLeaderElection bool
concurrent int
requeueDependency time.Duration
logLevel string
logJSON bool
logOptions logger.Options
watchAllNamespaces bool
)

flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&eventsAddr, "events-addr", "", "The address of the events receiver.")
flag.StringVar(&healthAddr, "health-addr", ":9440", "The address the health endpoint binds to.")
Expand All @@ -73,13 +72,18 @@ func main() {
"Enabling this will ensure there is only one active controller manager.")
flag.IntVar(&concurrent, "concurrent", 4, "The number of concurrent kustomize reconciles.")
flag.DurationVar(&requeueDependency, "requeue-dependency", 30*time.Second, "The interval at which failing dependencies are reevaluated.")
flag.StringVar(&logLevel, "log-level", "info", "Set logging level. Can be debug, info or error.")
flag.BoolVar(&logJSON, "log-json", false, "Set logging to JSON format.")
flag.BoolVar(&watchAllNamespaces, "watch-all-namespaces", true,
"Watch for custom resources in all namespaces, if set to false it will only watch the runtime namespace.")
flag.Bool("log-json", false, "Set logging to JSON format.")
flag.CommandLine.MarkDeprecated("log-json", "Please use --log-level=json instead.")
{
var fs goflag.FlagSet
logOptions.BindFlags(&fs)
flag.CommandLine.AddGoFlagSet(&fs)
}
flag.Parse()

ctrl.SetLogger(logger.NewLogger(logLevel, logJSON))
ctrl.SetLogger(logger.NewLogger(logOptions))

var eventRecorder *events.Recorder
if eventsAddr != "" {
Expand Down Expand Up @@ -118,7 +122,6 @@ func main() {

if err = (&controllers.KustomizationReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName(kustomizev1.KustomizationKind),
Scheme: mgr.GetScheme(),
EventRecorder: mgr.GetEventRecorderFor("kustomize-controller"),
ExternalEventRecorder: eventRecorder,
Expand Down

0 comments on commit 0b722a7

Please sign in to comment.