Skip to content

Commit d3ac622

Browse files
authored
Experimental configurations to override controller names (#494)
Since the early days of ACK, we've always relied on the `serviceID` to name the controller repositories. The way names, go modules, import paths, helm charts are named relied on this `serviceID`. Which was the main reason why some controllers had a bit of odd names, like `prometheusservice-controller` instead of `amp-controller`, `acmpca-controller` instead of `pca-controller`. This patch introduces experimental configurations that instructs the code generator to override the serviceID/servicePackageName when it comes to import paths/helm charts names etc... Related issue: aws-controllers-k8s/community#1411 Signed-off-by: Amine Hilaly <[email protected]> By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 947081f commit d3ac622

35 files changed

+103
-63
lines changed

cmd/ack-generate/command/common.go

-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ func getLatestAPIVersion(apiVersions []ackmetadata.ServiceVersion) (string, erro
9999

100100
// getServiceAccountName gets the service account name from the optional flag passed into ack-generate
101101
func getServiceAccountName() (string, error) {
102-
103102
if optServiceAccountName != "" {
104103
return optServiceAccountName, nil
105104
}

cmd/ack-generate/command/controller.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func FallBackFindServiceID(sdkDir, svcAlias string) (string, error) {
127127
defer f.Close()
128128
scanner := bufio.NewScanner(f)
129129
for scanner.Scan() {
130-
if strings.Contains(scanner.Text(), "serviceId") {
130+
if strings.Contains(scanner.Text(), "serviceId") && !strings.Contains(scanner.Text(), "serviceIdentifier") {
131131
getServiceID := strings.Split(scanner.Text(), ":")
132132
re := regexp.MustCompile(`[," \t]`)
133133
svcID := strings.ToLower(re.ReplaceAllString(getServiceID[1], ``))

pkg/config/config.go

+16
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ type Config struct {
4444
// only the service model name, but also the iface name to `PipesAPI`. See
4545
// https://github.com/aws/aws-sdk-go/blob/main/service/pipes/pipesiface/interface.go#L62
4646
SDKNames SDKNames `json:"sdk_names"`
47+
// ControllerName lets you specify a service alias override. This can be
48+
// used to only override the controller name exposed to the user. Meaning that
49+
// it will only change the module name, the import paths, and the controller
50+
// name. This is useful when the service identifier is not very user friendly
51+
// and you want to expose a more user friendly name to the user. e.g docdb ->
52+
// documentdb.
53+
// This will also change the helm chart and image names.
54+
ControllerName string `json:"controller_name,omitempty"`
4755
}
4856

4957
// SDKNames contains information on the SDK Client package. More precisely
@@ -56,6 +64,14 @@ type SDKNames struct {
5664
// model name is `opensearch` and the service package is called
5765
// `opensearchservice`.
5866
Model string `json:"model_name,omitempty"`
67+
// Package let you define the package name of the service client. This field
68+
// is optional and only needed for services such as documentdb where the service
69+
// controller is called `documentdb` and the package is called `docdb`.
70+
//
71+
// You might be wondering why not just use the `model_name` field... well the
72+
// answer is prometheusservice... the model name is `amp` and the service package
73+
// is called `prometheusservice`. :shrug:
74+
Package string `json:"package_name,omitempty"`
5975
// ClientInterface is the name of the interface that defines the "shape" of
6076
// the a sdk service client. e.g PipesAPI, LambdaAPI, etc...
6177
ClientInterface string `json:"client_interface,omitempty"`

pkg/generate/ack/release.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func Release(
100100
templateBasePaths,
101101
releaseIncludePaths,
102102
releaseCopyPaths,
103-
releaseFuncMap(m.MetaVars().ServicePackageName),
103+
releaseFuncMap(m.MetaVars().ControllerName),
104104
)
105105
metaVars := m.MetaVars()
106106

pkg/generate/templateset/vars.go

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ package templateset
1616
// MetaVars contains template variables that most templates need access to
1717
// that describe the service alias, its package name, etc
1818
type MetaVars struct {
19+
// ControllerName contains the exact string used to identify the ACK
20+
// controller in the aws-controllers-k8s project. This name is used as the
21+
// name of the ACK controller's module, repository and helm chart.
22+
ControllerName string
1923
// ServiceModelName contains the exact string used to identify the AWS
2024
// service API in the aws-sdk-go's models/apis/ directory. Note that some
2125
// APIs this name does not match the ServiceID. e.g. The AWS Step Functions

pkg/model/model.go

+22-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,24 @@ type Model struct {
5252
// MetaVars returns a MetaVars struct populated with metadata about the AWS
5353
// service API
5454
func (m *Model) MetaVars() templateset.MetaVars {
55+
controllerName := m.cfg.ControllerName
56+
if controllerName == "" {
57+
controllerName = m.servicePackageName
58+
}
59+
// NOTE(a-hilaly): I know this is a bit of a hack and it's confusing, but
60+
// long time ago, we assumed that model_name is always equal to the service
61+
// name. This is not the case anymore, prometheusservice and documentdb
62+
// are examples of services that have different model names.
63+
//
64+
// TODO(a-hilaly): We should probably rework all this naming stuff to be
65+
// more consistent. To whoever is reading this, I'm sorry.
66+
servicePackageName := m.servicePackageName
67+
if m.cfg.SDKNames.Package != "" {
68+
servicePackageName = m.cfg.SDKNames.Package
69+
}
5570
return templateset.MetaVars{
56-
ServicePackageName: m.servicePackageName,
71+
ControllerName: controllerName,
72+
ServicePackageName: servicePackageName,
5773
ServiceID: m.SDKAPI.ServiceID(),
5874
ServiceModelName: m.cfg.SDKNames.Model,
5975
APIGroup: m.APIGroup(),
@@ -943,7 +959,11 @@ func (m *Model) APIGroup() string {
943959
if m.SDKAPI.APIGroupSuffix != "" {
944960
suffix = m.SDKAPI.APIGroupSuffix
945961
}
946-
return fmt.Sprintf("%s.%s", m.servicePackageName, suffix)
962+
name := m.GetConfig().ControllerName
963+
if name == "" {
964+
name = m.servicePackageName
965+
}
966+
return fmt.Sprintf("%s.%s", name, suffix)
947967
}
948968

949969
// ClientInterfaceTypeName returns the name of the aws-sdk-go primary API

templates/cmd/controller/main.go.tpl

+6-5
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,27 @@ import (
2525
If these referenced types are not added to scheme, this service controller will not be able to read
2626
resources across service controller. */ -}}
2727
{{- $servicePackageName := .ServicePackageName }}
28+
{{- $controllerName := .ControllerName }}
2829
{{- $apiVersion := .APIVersion }}
2930
{{- range $referencedServiceName := .ReferencedServiceNames }}
3031
{{- if not (eq $referencedServiceName $servicePackageName) }}
3132
{{ $referencedServiceName }}apitypes "github.com/aws-controllers-k8s/{{ $referencedServiceName }}-controller/apis/{{ $apiVersion }}"
3233
{{- end }}
3334
{{- end }}
3435

35-
svcresource "github.com/aws-controllers-k8s/{{ .ServicePackageName }}-controller/pkg/resource"
36+
svcresource "github.com/aws-controllers-k8s/{{ .ControllerName }}-controller/pkg/resource"
3637
svcsdk "github.com/aws/aws-sdk-go/service/{{ .ServicePackageName }}"
37-
svctypes "github.com/aws-controllers-k8s/{{ .ServicePackageName }}-controller/apis/{{ .APIVersion }}"
38+
svctypes "github.com/aws-controllers-k8s/{{ .ControllerName }}-controller/apis/{{ .APIVersion }}"
3839

3940
{{/* TODO(a-hilaly): import apis/* packages to register webhooks */}}
40-
{{range $crdName := .SnakeCasedCRDNames }}_ "github.com/aws-controllers-k8s/{{ $servicePackageName }}-controller/pkg/resource/{{ $crdName }}"
41+
{{range $crdName := .SnakeCasedCRDNames }}_ "github.com/aws-controllers-k8s/{{ $controllerName }}-controller/pkg/resource/{{ $crdName }}"
4142
{{end}}
42-
"github.com/aws-controllers-k8s/{{ .ServicePackageName }}-controller/pkg/version"
43+
"github.com/aws-controllers-k8s/{{ .ControllerName }}-controller/pkg/version"
4344
)
4445

4546
var (
4647
awsServiceAPIGroup = "{{ .APIGroup }}"
47-
awsServiceAlias = "{{ .ServicePackageName }}"
48+
awsServiceAlias = "{{ .ControllerName }}"
4849
awsServiceEndpointsID = svcsdk.EndpointsID
4950
scheme = runtime.NewScheme()
5051
setupLog = ctrlrt.Log.WithName("setup")

templates/config/controller/deployment.yaml.tpl

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@ metadata:
66
apiVersion: apps/v1
77
kind: Deployment
88
metadata:
9-
name: ack-{{ .ServicePackageName }}-controller
9+
name: ack-{{ .ControllerName }}-controller
1010
namespace: ack-system
1111
labels:
12-
app.kubernetes.io/name: ack-{{ .ServicePackageName }}-controller
12+
app.kubernetes.io/name: ack-{{ .ControllerName }}-controller
1313
app.kubernetes.io/part-of: ack-system
1414
spec:
1515
selector:
1616
matchLabels:
17-
app.kubernetes.io/name: ack-{{ .ServicePackageName }}-controller
17+
app.kubernetes.io/name: ack-{{ .ControllerName }}-controller
1818
replicas: 1
1919
template:
2020
metadata:
2121
labels:
22-
app.kubernetes.io/name: ack-{{ .ServicePackageName }}-controller
22+
app.kubernetes.io/name: ack-{{ .ControllerName }}-controller
2323
spec:
2424
containers:
2525
- command:

templates/config/controller/olm-kustomization.yaml.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ patches:
1515
target:
1616
group: apps
1717
kind: Deployment
18-
name: ack-{{ .ServicePackageName }}-controller
18+
name: ack-{{ .ControllerName }}-controller
1919
version: v1
2020
- path: user-env.yaml

templates/config/controller/service.yaml.tpl

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
apiVersion: v1
22
kind: Service
33
metadata:
4-
name: ack-{{ .ServicePackageName }}-metrics-service
4+
name: ack-{{ .ControllerName }}-metrics-service
55
namespace: ack-system
66
spec:
77
selector:
8-
app.kubernetes.io/name: ack-{{ .ServicePackageName }}-controller
8+
app.kubernetes.io/name: ack-{{ .ControllerName }}-controller
99
ports:
1010
- name: metricsport
1111
port: 8080
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apiVersion: apps/v1
22
kind: Deployment
33
metadata:
4-
name: ack-{{.ServicePackageName}}-controller
4+
name: ack-{{.ControllerName}}-controller
55
namespace: {{.Annotations.SuggestedNamespace}}
66
spec:
77
template:
@@ -10,8 +10,8 @@ spec:
1010
- name: controller
1111
envFrom:
1212
- configMapRef:
13-
name: ack-{{.ServicePackageName}}-user-config
13+
name: ack-{{.ControllerName}}-user-config
1414
optional: false
1515
- secretRef:
16-
name: ack-{{.ServicePackageName}}-user-secrets
16+
name: ack-{{.ControllerName}}-user-secrets
1717
optional: true

templates/config/manifests/bases/clusterserviceversion.yaml.tpl

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ metadata:
1616
operatorframework.io/os.linux: supported
1717
operatorframework.io/arch.amd64: supported
1818
operatorframework.io/arch.arm64: supported
19-
name: ack-{{.ServicePackageName }}-controller.v0.0.0
19+
name: ack-{{.ControllerName }}-controller.v0.0.0
2020
namespace: placeholder
2121
spec:
2222
apiservicedefinitions: {}
@@ -27,7 +27,7 @@ spec:
2727
name: {{ ToLower .Plural }}.{{$.APIGroup}}
2828
version: {{$.APIVersion}}
2929
displayName: {{.Kind}}
30-
description: {{.Kind}} represents the state of an AWS {{$.ServicePackageName}} {{.Kind}} resource.
30+
description: {{.Kind}} represents the state of an AWS {{$.ControllerName}} {{.Kind}} resource.
3131
{{- end}}
3232
description: '{{ .Description }}'
3333
displayName: {{ .DisplayName}}
@@ -46,7 +46,7 @@ spec:
4646
type: {{ .Type }}
4747
{{- end}}
4848
keywords:
49-
- {{.ServicePackageName}}
49+
- {{.ControllerName}}
5050
{{- range .Common.Keywords}}
5151
- {{ . }}
5252
{{- end}}

templates/config/overlays/namespaced/kustomization.yaml.tpl

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ patches:
66
group: rbac.authorization.k8s.io
77
version: v1
88
kind: ClusterRole
9-
name: ack-{{ .ServicePackageName }}-controller
9+
name: ack-{{ .ControllerName }}-controller
1010
- path: role-binding.json
1111
target:
1212
group: rbac.authorization.k8s.io
1313
version: v1
1414
kind: ClusterRoleBinding
15-
name: ack-{{ .ServicePackageName }}-controller-rolebinding
15+
name: ack-{{ .ControllerName }}-controller-rolebinding

templates/config/rbac/cluster-role-binding.yaml.tpl

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
apiVersion: rbac.authorization.k8s.io/v1
22
kind: ClusterRoleBinding
33
metadata:
4-
name: ack-{{ .ServicePackageName }}-controller-rolebinding
4+
name: ack-{{ .ControllerName }}-controller-rolebinding
55
roleRef:
66
apiGroup: rbac.authorization.k8s.io
77
kind: ClusterRole
8-
name: ack-{{ .ServicePackageName }}-controller
8+
name: ack-{{ .ControllerName }}-controller
99
subjects:
1010
- kind: ServiceAccount
1111
name: {{ .ServiceAccountName }}

templates/config/rbac/leader-election-role-binding.yaml.tpl

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ apiVersion: rbac.authorization.k8s.io/v1
33
kind: RoleBinding
44
metadata:
55
namespace: ack-system
6-
name: {{.ServicePackageName}}-leader-election-rolebinding
6+
name: {{.ControllerName}}-leader-election-rolebinding
77
roleRef:
88
apiGroup: rbac.authorization.k8s.io
99
kind: Role
10-
name: {{.ServicePackageName}}-leader-election-role
10+
name: {{.ControllerName}}-leader-election-role
1111
subjects:
1212
- kind: ServiceAccount
1313
name: {{.ServiceAccountName}}

templates/config/rbac/leader-election-role.yaml.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
apiVersion: rbac.authorization.k8s.io/v1
33
kind: Role
44
metadata:
5-
name: {{.ServicePackageName}}-leader-election-role
5+
name: {{.ControllerName}}-leader-election-role
66
namespace: ack-system
77
rules:
88
- apiGroups:

templates/config/rbac/role-reader.yaml.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apiVersion: rbac.authorization.k8s.io/v1
33
kind: Role
44
metadata:
55
creationTimestamp: null
6-
name: ack-{{ .ServicePackageName }}-reader
6+
name: ack-{{ .ControllerName }}-reader
77
namespace: default
88
rules:
99
- apiGroups:

templates/config/rbac/role-writer.yaml.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apiVersion: rbac.authorization.k8s.io/v1
33
kind: Role
44
metadata:
55
creationTimestamp: null
6-
name: ack-{{ .ServicePackageName }}-writer
6+
name: ack-{{ .ControllerName }}-writer
77
namespace: default
88
rules:
99
- apiGroups:

templates/helm/Chart.yaml.tpl

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
apiVersion: v1
2-
name: {{ .ServicePackageName }}-chart
2+
name: {{ .ControllerName }}-chart
33
description: A Helm chart for the ACK service controller for {{ .Metadata.Service.FullName }} ({{ .Metadata.Service.ShortName }})
44
version: {{ .ReleaseVersion }}
55
appVersion: {{ .ReleaseVersion }}
6-
home: https://github.com/aws-controllers-k8s/{{ .ServicePackageName }}-controller
6+
home: https://github.com/aws-controllers-k8s/{{ .ControllerName }}-controller
77
icon: https://raw.githubusercontent.com/aws/eks-charts/master/docs/logo/aws.png
88
sources:
9-
- https://github.com/aws-controllers-k8s/{{ .ServicePackageName }}-controller
9+
- https://github.com/aws-controllers-k8s/{{ .ControllerName }}-controller
1010
maintainers:
1111
- name: ACK Admins
1212
url: https://github.com/orgs/aws-controllers-k8s/teams/ack-admin
1313
- name: {{ .Metadata.Service.ShortName }} Admins
14-
url: https://github.com/orgs/aws-controllers-k8s/teams/{{ .ServicePackageName }}-maintainer
14+
url: https://github.com/orgs/aws-controllers-k8s/teams/{{ .ControllerName }}-maintainer
1515
keywords:
1616
- aws
1717
- kubernetes
18-
- {{ .ServicePackageName }}
18+
- {{ .ControllerName }}
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
apiVersion: rbac.authorization.k8s.io/v1
22
kind: ClusterRoleBinding
33
metadata:
4-
name: ack-namespaces-cache-{{ .ServicePackageName }}-controller
4+
name: ack-namespaces-cache-{{ .ControllerName }}-controller
55
roleRef:
66
kind: ClusterRole
77
apiGroup: rbac.authorization.k8s.io
8-
name: ack-namespaces-cache-{{ .ServicePackageName }}-controller
8+
name: ack-namespaces-cache-{{ .ControllerName }}-controller
99
subjects:
1010
- kind: ServiceAccount
11-
name: ack-{{ .ServicePackageName }}-controller
11+
name: ack-{{ .ControllerName }}-controller
1212
namespace: {{ "{{ .Release.Namespace }}" }}
1313
---
1414
apiVersion: rbac.authorization.k8s.io/v1
1515
kind: RoleBinding
1616
metadata:
17-
name: ack-configmaps-cache-{{ .ServicePackageName }}-controller
17+
name: ack-configmaps-cache-{{ .ControllerName }}-controller
1818
namespace: {{ "{{ .Release.Namespace }}" }}
1919
roleRef:
2020
kind: Role
2121
apiGroup: rbac.authorization.k8s.io
22-
name: ack-configmaps-cache-{{ .ServicePackageName }}-controller
22+
name: ack-configmaps-cache-{{ .ControllerName }}-controller
2323
subjects:
2424
- kind: ServiceAccount
25-
name: ack-{{ .ServicePackageName }}-controller
25+
name: ack-{{ .ControllerName }}-controller
2626
namespace: {{ "{{ .Release.Namespace }}" }}

templates/helm/templates/caches-role.yaml.tpl

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apiVersion: rbac.authorization.k8s.io/v1
22
kind: ClusterRole
33
metadata:
4-
name: ack-namespaces-cache-{{ .ServicePackageName }}-controller
4+
name: ack-namespaces-cache-{{ .ControllerName }}-controller
55
rules:
66
- apiGroups:
77
- ""
@@ -15,7 +15,7 @@ rules:
1515
apiVersion: rbac.authorization.k8s.io/v1
1616
kind: Role
1717
metadata:
18-
name: ack-configmaps-cache-{{ .ServicePackageName }}-controller
18+
name: ack-configmaps-cache-{{ .ControllerName }}-controller
1919
namespace: {{ "{{ .Release.Namespace }}" }}
2020
rules:
2121
- apiGroups:

templates/helm/templates/cluster-role-binding.yaml.tpl

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ metadata:
66
roleRef:
77
kind: ClusterRole
88
apiGroup: rbac.authorization.k8s.io
9-
name: ack-{{ .ServicePackageName }}-controller
9+
name: ack-{{ .ControllerName }}-controller
1010
subjects:
1111
- kind: ServiceAccount
1212
name: {{ IncludeTemplate "service-account.name" }}
@@ -27,7 +27,7 @@ metadata:
2727
roleRef:
2828
kind: Role
2929
apiGroup: rbac.authorization.k8s.io
30-
name: ack-{{ .ServicePackageName }}-controller
30+
name: ack-{{ .ControllerName }}-controller
3131
subjects:
3232
- kind: ServiceAccount
3333
name: {{ "{{ $serviceAccountName }}" }}

0 commit comments

Comments
 (0)