Skip to content

Commit

Permalink
Upgrade controller-runtime, hack fix for gen
Browse files Browse the repository at this point in the history
controller-runtime 0.4.1 fixed the issue where they generated types as
Any which was an invalid type
(kubernetes-sigs/controller-tools#505) however
that results in the type for proxy-defaults.config being "byte" which
fails when creating proxy-defaults.

I played around a long time trying to find a type that generates the CRD
as expected and can be unmarshalled as expected and nothing worked so
for now I think it's best to keep it as json.RawMessage and then patch
the generated CRD.
  • Loading branch information
lkysow committed Nov 27, 2020
1 parent d04a36b commit a4c3833
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 13 deletions.
5 changes: 3 additions & 2 deletions config/crd/bases/consul.hashicorp.com_proxydefaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.4.0
controller-gen.kubebuilder.io/version: v0.4.1
creationTimestamp: null
name: proxydefaults.consul.hashicorp.com
spec:
Expand Down Expand Up @@ -43,7 +43,8 @@ spec:
properties:
config:
description: Config is an arbitrary map of configuration values used by Connect proxies. Any values that your proxy allows can be configured globally here. Supports JSON config values. See https://www.consul.io/docs/connect/proxies/envoy#configuration-formatting
type: Any
format: byte
type: string
expose:
description: Expose controls the default expose path configuration for Envoy.
properties:
Expand Down
2 changes: 1 addition & 1 deletion config/crd/bases/consul.hashicorp.com_servicedefaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.4.0
controller-gen.kubebuilder.io/version: v0.4.1
creationTimestamp: null
name: servicedefaults.consul.hashicorp.com
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.4.0
controller-gen.kubebuilder.io/version: v0.4.1
creationTimestamp: null
name: serviceintentions.consul.hashicorp.com
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.4.0
controller-gen.kubebuilder.io/version: v0.4.1
creationTimestamp: null
name: serviceresolvers.consul.hashicorp.com
spec:
Expand Down
2 changes: 1 addition & 1 deletion config/crd/bases/consul.hashicorp.com_servicerouters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.4.0
controller-gen.kubebuilder.io/version: v0.4.1
creationTimestamp: null
name: servicerouters.consul.hashicorp.com
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.4.0
controller-gen.kubebuilder.io/version: v0.4.1
creationTimestamp: null
name: servicesplitters.consul.hashicorp.com
spec:
Expand Down
6 changes: 0 additions & 6 deletions config/webhook/manifests.v1beta1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ metadata:
name: mutating-webhook-configuration
webhooks:
- clientConfig:
caBundle: Cg==
service:
name: webhook-service
namespace: system
Expand All @@ -26,7 +25,6 @@ webhooks:
- proxydefaults
sideEffects: None
- clientConfig:
caBundle: Cg==
service:
name: webhook-service
namespace: system
Expand All @@ -45,7 +43,6 @@ webhooks:
- servicedefaults
sideEffects: None
- clientConfig:
caBundle: Cg==
service:
name: webhook-service
namespace: system
Expand All @@ -64,7 +61,6 @@ webhooks:
- serviceintentions
sideEffects: None
- clientConfig:
caBundle: Cg==
service:
name: webhook-service
namespace: system
Expand All @@ -83,7 +79,6 @@ webhooks:
- serviceresolvers
sideEffects: None
- clientConfig:
caBundle: Cg==
service:
name: webhook-service
namespace: system
Expand All @@ -102,7 +97,6 @@ webhooks:
- servicerouters
sideEffects: None
- clientConfig:
caBundle: Cg==
service:
name: webhook-service
namespace: system
Expand Down
12 changes: 12 additions & 0 deletions hack/crds-to-consul-helm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ func realMain(helmPath string) error {
// Add {{- if .Values.controller.enabled }} {{- end }} wrapper.
contents = fmt.Sprintf("{{- if .Values.controller.enabled }}\n%s{{- end }}\n", contents)

// Hack: handle an issue where controller-gen generates the wrong type
// for the proxydefaults.config struct.
contents = strings.Replace(contents, proxyDefaultsSearch, proxyDefaultsReplace, 1)

// Add labels, this is hacky because we're relying on the line number
// but it means we don't need to regex or yaml parse.
splitOnNewlines := strings.Split(contents, "\n")
Expand All @@ -70,6 +74,14 @@ func realMain(helmPath string) error {
})
}

var proxyDefaultsSearch = ` description: Config is an arbitrary map of configuration values used by Connect proxies. Any values that your proxy allows can be configured globally here. Supports JSON config values. See https://www.consul.io/docs/connect/proxies/envoy#configuration-formatting
format: byte
type: string
`
var proxyDefaultsReplace = ` description: Config is an arbitrary map of configuration values used by Connect proxies. Any values that your proxy allows can be configured globally here. Supports JSON config values. See https://www.consul.io/docs/connect/proxies/envoy#configuration-formatting
type: object
`

func printf(format string, args ...interface{}) {
fmt.Println(fmt.Sprintf(format, args...))
}

0 comments on commit a4c3833

Please sign in to comment.