diff --git a/api/go.mod b/api/go.mod index f7aef580..fccd5c16 100644 --- a/api/go.mod +++ b/api/go.mod @@ -3,8 +3,8 @@ module github.com/fluxcd/kustomize-controller/api go 1.15 require ( - github.com/fluxcd/pkg/apis/meta v0.6.0 - github.com/fluxcd/pkg/runtime v0.7.0 + github.com/fluxcd/pkg/apis/meta v0.7.0 + github.com/fluxcd/pkg/runtime v0.8.0 k8s.io/api v0.20.2 k8s.io/apimachinery v0.20.2 sigs.k8s.io/controller-runtime v0.8.0 diff --git a/api/go.sum b/api/go.sum index eed88ed3..435ae817 100644 --- a/api/go.sum +++ b/api/go.sum @@ -88,10 +88,10 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7 github.com/evanphx/json-patch v4.5.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= github.com/evanphx/json-patch v4.9.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= -github.com/fluxcd/pkg/apis/meta v0.6.0 h1:3ETc/Yz4qXGKLj+Iti6vKFwVE024WX+Jr+jIHlxj7zs= -github.com/fluxcd/pkg/apis/meta v0.6.0/go.mod h1:yHuY8kyGHYz22I0jQzqMMGCcHViuzC/WPdo9Gisk8Po= -github.com/fluxcd/pkg/runtime v0.7.0 h1:AMzqHGae0zqDQAmKwa1htjStk2wphwWF0xQw/zD3FY4= -github.com/fluxcd/pkg/runtime v0.7.0/go.mod h1:1dzGFwtowST5AIW5i9f0Pn0fMhCmOHFyBizuPJSKX+s= +github.com/fluxcd/pkg/apis/meta v0.7.0 h1:5e8gm4OLqjuKWdrOIY5DEEsjcwzyJFK8rCDesJ+V8IY= +github.com/fluxcd/pkg/apis/meta v0.7.0/go.mod h1:yHuY8kyGHYz22I0jQzqMMGCcHViuzC/WPdo9Gisk8Po= +github.com/fluxcd/pkg/runtime v0.8.0 h1:cnSBZJLcXlKgjXpFFFExu+4ZncIxmPgNIx+ErLcCLnA= +github.com/fluxcd/pkg/runtime v0.8.0/go.mod h1:tQwEN+RESjJmtwSSv7I+6bkNM9raIXpGsCjruaIVX6A= github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= diff --git a/api/v1beta1/kustomization_types.go b/api/v1beta1/kustomization_types.go index df0949f8..9b2672e2 100644 --- a/api/v1beta1/kustomization_types.go +++ b/api/v1beta1/kustomization_types.go @@ -19,7 +19,6 @@ package v1beta1 import ( "time" - corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" @@ -66,7 +65,7 @@ type KustomizationSpec struct { // A list of resources to be included in the health assessment. // +optional - HealthChecks []CrossNamespaceObjectReference `json:"healthChecks,omitempty"` + HealthChecks []meta.NamespacedObjectKindReference `json:"healthChecks,omitempty"` // A list of images used to override or set the name and tag for container images. // +optional @@ -115,7 +114,7 @@ type Decryption struct { // The secret name containing the private OpenPGP keys used for decryption. // +optional - SecretRef *corev1.LocalObjectReference `json:"secretRef,omitempty"` + SecretRef *meta.LocalObjectReference `json:"secretRef,omitempty"` } // Image contains the name, new name and new tag that will replace the original container image. @@ -144,7 +143,7 @@ type KubeConfig struct { // binaries and credentials to the Pod that is responsible for reconciling // the Kustomization. // +required - SecretRef corev1.LocalObjectReference `json:"secretRef,omitempty"` + SecretRef meta.LocalObjectReference `json:"secretRef,omitempty"` } // KustomizationStatus defines the observed state of a kustomization. diff --git a/api/v1beta1/reference_types.go b/api/v1beta1/reference_types.go index 188ecee7..30304862 100644 --- a/api/v1beta1/reference_types.go +++ b/api/v1beta1/reference_types.go @@ -16,26 +16,6 @@ limitations under the License. package v1beta1 -// CrossNamespaceObjectReference contains enough information to let you locate the -// typed referenced object at cluster level -type CrossNamespaceObjectReference struct { - // API version of the referent, defaults to 'apps/v1' - // +optional - APIVersion string `json:"apiVersion,omitempty"` - - // Kind of the referent - // +required - Kind string `json:"kind"` - - // Name of the referent - // +required - Name string `json:"name"` - - // Namespace of the referent - // +optional - Namespace string `json:"namespace,omitempty"` -} - // CrossNamespaceSourceReference contains enough information to let you locate the // typed referenced object at cluster level type CrossNamespaceSourceReference struct { diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go index 70ff6e3e..0a0fa977 100644 --- a/api/v1beta1/zz_generated.deepcopy.go +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -21,27 +21,12 @@ limitations under the License. package v1beta1 import ( + "github.com/fluxcd/pkg/apis/meta" "github.com/fluxcd/pkg/runtime/dependency" - corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" ) -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *CrossNamespaceObjectReference) DeepCopyInto(out *CrossNamespaceObjectReference) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CrossNamespaceObjectReference. -func (in *CrossNamespaceObjectReference) DeepCopy() *CrossNamespaceObjectReference { - if in == nil { - return nil - } - out := new(CrossNamespaceObjectReference) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *CrossNamespaceSourceReference) DeepCopyInto(out *CrossNamespaceSourceReference) { *out = *in @@ -62,7 +47,7 @@ func (in *Decryption) DeepCopyInto(out *Decryption) { *out = *in if in.SecretRef != nil { in, out := &in.SecretRef, &out.SecretRef - *out = new(corev1.LocalObjectReference) + *out = new(meta.LocalObjectReference) **out = **in } } @@ -188,7 +173,7 @@ func (in *KustomizationSpec) DeepCopyInto(out *KustomizationSpec) { } if in.HealthChecks != nil { in, out := &in.HealthChecks, &out.HealthChecks - *out = make([]CrossNamespaceObjectReference, len(*in)) + *out = make([]meta.NamespacedObjectKindReference, len(*in)) copy(*out, *in) } if in.Images != nil { diff --git a/config/crd/bases/kustomize.toolkit.fluxcd.io_kustomizations.yaml b/config/crd/bases/kustomize.toolkit.fluxcd.io_kustomizations.yaml index 4c6636a3..8216610d 100644 --- a/config/crd/bases/kustomize.toolkit.fluxcd.io_kustomizations.yaml +++ b/config/crd/bases/kustomize.toolkit.fluxcd.io_kustomizations.yaml @@ -62,9 +62,10 @@ spec: used for decryption. properties: name: - description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names - TODO: Add other useful fields. apiVersion, kind, uid?' + description: Name of the referent type: string + required: + - name type: object required: - provider @@ -90,11 +91,12 @@ spec: healthChecks: description: A list of resources to be included in the health assessment. items: - description: CrossNamespaceObjectReference contains enough information - to let you locate the typed referenced object at cluster level + description: NamespacedObjectKindReference contains enough information + to let you locate the typed referenced object in any namespace properties: apiVersion: - description: API version of the referent, defaults to 'apps/v1' + description: API version of the referent, if not specified the + Kubernetes preferred version will be used type: string kind: description: Kind of the referent @@ -103,7 +105,8 @@ spec: description: Name of the referent type: string namespace: - description: Namespace of the referent + description: Namespace of the referent, when not specified it + acts as LocalObjectReference type: string required: - kind @@ -153,9 +156,10 @@ spec: for reconciling the Kustomization. properties: name: - description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names - TODO: Add other useful fields. apiVersion, kind, uid?' + description: Name of the referent type: string + required: + - name type: object type: object path: diff --git a/controllers/kustomization_healthcheck.go b/controllers/kustomization_healthcheck.go index 5a370ad5..e6d3f13c 100644 --- a/controllers/kustomization_healthcheck.go +++ b/controllers/kustomization_healthcheck.go @@ -22,6 +22,7 @@ import ( "strings" "time" + "github.com/fluxcd/pkg/apis/meta" "k8s.io/apimachinery/pkg/runtime/schema" "sigs.k8s.io/cli-utils/pkg/kstatus/polling" "sigs.k8s.io/cli-utils/pkg/kstatus/polling/aggregator" @@ -93,7 +94,7 @@ func (hc *KustomizeHealthCheck) Assess(pollInterval time.Duration) error { return nil } -func (hc *KustomizeHealthCheck) toObjMetadata(cr []kustomizev1.CrossNamespaceObjectReference) ([]object.ObjMetadata, error) { +func (hc *KustomizeHealthCheck) toObjMetadata(cr []meta.NamespacedObjectKindReference) ([]object.ObjMetadata, error) { oo := []object.ObjMetadata{} for _, c := range cr { // For backwards compatibility diff --git a/docs/api/kustomize.md b/docs/api/kustomize.md index f378a809..45b5cd6a 100644 --- a/docs/api/kustomize.md +++ b/docs/api/kustomize.md @@ -155,8 +155,8 @@ bool healthChecks
- -[]CrossNamespaceObjectReference + +[]github.com/fluxcd/pkg/apis/meta.NamespacedObjectKindReference @@ -278,74 +278,6 @@ KustomizationStatus -

CrossNamespaceObjectReference -

-

-(Appears on: -KustomizationSpec) -

-

CrossNamespaceObjectReference contains enough information to let you locate the -typed referenced object at cluster level

-
-
- - - - - - - - - - - - - - - - - - - - - - - - - -
FieldDescription
-apiVersion
- -string - -
-(Optional) -

API version of the referent, defaults to ‘apps/v1’

-
-kind
- -string - -
-

Kind of the referent

-
-name
- -string - -
-

Name of the referent

-
-namespace
- -string - -
-(Optional) -

Namespace of the referent

-
-
-

CrossNamespaceSourceReference

@@ -446,8 +378,8 @@ string secretRef
- -Kubernetes core/v1.LocalObjectReference + +github.com/fluxcd/pkg/apis/meta.LocalObjectReference @@ -535,8 +467,8 @@ string secretRef
- -Kubernetes core/v1.LocalObjectReference + +github.com/fluxcd/pkg/apis/meta.LocalObjectReference @@ -659,8 +591,8 @@ bool healthChecks
- -[]CrossNamespaceObjectReference + +[]github.com/fluxcd/pkg/apis/meta.NamespacedObjectKindReference diff --git a/docs/spec/v1beta1/kustomization.md b/docs/spec/v1beta1/kustomization.md index f18f67ad..f2e74849 100644 --- a/docs/spec/v1beta1/kustomization.md +++ b/docs/spec/v1beta1/kustomization.md @@ -42,7 +42,7 @@ type KustomizationSpec struct { // A list of resources to be included in the health assessment. // +optional - HealthChecks []CrossNamespaceObjectReference `json:"healthChecks,omitempty"` + HealthChecks []meta.NamespacedObjectKindReference `json:"healthChecks,omitempty"` // A list of images used to override or set the name and tag for container images. // +optional @@ -91,7 +91,7 @@ type Decryption struct { // The secret name containing the private OpenPGP keys used for decryption. // +optional - SecretRef *corev1.LocalObjectReference `json:"secretRef,omitempty"` + SecretRef *meta.LocalObjectReference `json:"secretRef,omitempty"` } ``` @@ -109,7 +109,7 @@ type KubeConfig struct { // binaries and credentials to the Pod that is responsible for reconciling // the Kustomization. // +required - SecretRef corev1.LocalObjectReference `json:"secretRef,omitempty"` + SecretRef meta.LocalObjectReference `json:"secretRef,omitempty"` } ``` diff --git a/go.mod b/go.mod index 125dcd7e..852adc6f 100644 --- a/go.mod +++ b/go.mod @@ -7,8 +7,8 @@ replace github.com/fluxcd/kustomize-controller/api => ./api require ( github.com/cyphar/filepath-securejoin v0.2.2 github.com/fluxcd/kustomize-controller/api v0.6.3 - github.com/fluxcd/pkg/apis/meta v0.6.0 - github.com/fluxcd/pkg/runtime v0.7.0 + github.com/fluxcd/pkg/apis/meta v0.7.0 + github.com/fluxcd/pkg/runtime v0.8.0 github.com/fluxcd/pkg/testserver v0.0.2 github.com/fluxcd/pkg/untar v0.0.5 github.com/fluxcd/source-controller/api v0.6.3 diff --git a/go.sum b/go.sum index 33f41074..6ad0f1fb 100644 --- a/go.sum +++ b/go.sum @@ -189,10 +189,11 @@ github.com/fatih/camelcase v1.0.0/go.mod h1:yN2Sb0lFhZJUdVvtELVWefmrXpuZESvPmqwo github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= -github.com/fluxcd/pkg/apis/meta v0.6.0 h1:3ETc/Yz4qXGKLj+Iti6vKFwVE024WX+Jr+jIHlxj7zs= github.com/fluxcd/pkg/apis/meta v0.6.0/go.mod h1:yHuY8kyGHYz22I0jQzqMMGCcHViuzC/WPdo9Gisk8Po= -github.com/fluxcd/pkg/runtime v0.7.0 h1:AMzqHGae0zqDQAmKwa1htjStk2wphwWF0xQw/zD3FY4= -github.com/fluxcd/pkg/runtime v0.7.0/go.mod h1:1dzGFwtowST5AIW5i9f0Pn0fMhCmOHFyBizuPJSKX+s= +github.com/fluxcd/pkg/apis/meta v0.7.0 h1:5e8gm4OLqjuKWdrOIY5DEEsjcwzyJFK8rCDesJ+V8IY= +github.com/fluxcd/pkg/apis/meta v0.7.0/go.mod h1:yHuY8kyGHYz22I0jQzqMMGCcHViuzC/WPdo9Gisk8Po= +github.com/fluxcd/pkg/runtime v0.8.0 h1:cnSBZJLcXlKgjXpFFFExu+4ZncIxmPgNIx+ErLcCLnA= +github.com/fluxcd/pkg/runtime v0.8.0/go.mod h1:tQwEN+RESjJmtwSSv7I+6bkNM9raIXpGsCjruaIVX6A= github.com/fluxcd/pkg/testserver v0.0.2 h1:SoaMtO9cE5p/wl2zkGudzflnEHd9mk68CGjZOo7w0Uk= github.com/fluxcd/pkg/testserver v0.0.2/go.mod h1:pgUZTh9aQ44FSTQo+5NFlh7YMbUfdz1B80DalW7k96Y= github.com/fluxcd/pkg/untar v0.0.5 h1:UGI3Ch1UIEIaqQvMicmImL1s9npQa64DJ/ozqHKB7gk= diff --git a/main.go b/main.go index c8758918..1c5ead47 100644 --- a/main.go +++ b/main.go @@ -17,7 +17,6 @@ limitations under the License. package main import ( - goflag "flag" "os" "time" @@ -29,6 +28,7 @@ import ( ctrl "sigs.k8s.io/controller-runtime" crtlmetrics "sigs.k8s.io/controller-runtime/pkg/metrics" + "github.com/fluxcd/pkg/runtime/client" "github.com/fluxcd/pkg/runtime/events" "github.com/fluxcd/pkg/runtime/logger" "github.com/fluxcd/pkg/runtime/metrics" @@ -61,11 +61,11 @@ func main() { enableLeaderElection bool concurrent int requeueDependency time.Duration + clientOptions client.Options logOptions logger.Options watchAllNamespaces bool - kubeapiQPS float64 - kubeapiBurst int ) + 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.") @@ -77,14 +77,9 @@ func main() { 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.Float64Var(&kubeapiQPS, "kube-api-qps", 20.0, "QPS to use while talking with kubernetes API.") - flag.IntVar(&kubeapiBurst, "kube-api-burst", 50, "Burst to use while talking with kubernetes API server.") flag.CommandLine.MarkDeprecated("log-json", "Please use --log-encoding=json instead.") - { - var fs goflag.FlagSet - logOptions.BindFlags(&fs) - flag.CommandLine.AddGoFlagSet(&fs) - } + clientOptions.BindFlags(flag.CommandLine) + logOptions.BindFlags(flag.CommandLine) flag.Parse() ctrl.SetLogger(logger.NewLogger(logOptions)) @@ -107,10 +102,7 @@ func main() { watchNamespace = os.Getenv("RUNTIME_NAMESPACE") } - restConfig := ctrl.GetConfigOrDie() - restConfig.QPS = float32(kubeapiQPS) - restConfig.Burst = kubeapiBurst - + restConfig := client.GetConfigOrDie(clientOptions) mgr, err := ctrl.NewManager(restConfig, ctrl.Options{ Scheme: scheme, MetricsBindAddress: metricsAddr,