Skip to content

Commit 9191f9d

Browse files
authored
add real versions to controller main.go (#321)
I'd left a TODO in the main.go template for controllers to fill in their GitVersion, GitCommit and BuildDate information properly. Just now getting around to this... Issue: aws-controllers-k8s/community#1171 Signed-off-by: Jay Pipes <[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 fc5620c commit 9191f9d

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

templates/cmd/controller/main.go.tpl

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package main
55
import (
66
"os"
77

8+
ackv1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1"
89
ackcfg "github.com/aws-controllers-k8s/runtime/pkg/config"
910
ackrt "github.com/aws-controllers-k8s/runtime/pkg/runtime"
1011
ackrtutil "github.com/aws-controllers-k8s/runtime/pkg/util"
@@ -16,7 +17,6 @@ import (
1617
ctrlrtmetrics "sigs.k8s.io/controller-runtime/pkg/metrics"
1718
svcsdk "github.com/aws/aws-sdk-go/service/{{ .ServicePackageName }}"
1819

19-
ackv1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1"
2020
svcresource "github.com/aws-controllers-k8s/{{ .ServicePackageName }}-controller/pkg/resource"
2121
svctypes "github.com/aws-controllers-k8s/{{ .ServicePackageName }}-controller/apis/{{ .APIVersion }}"
2222
{{- /* Import the go types from service controllers whose resources are referenced in this service controller.
@@ -26,20 +26,21 @@ resources across service controller. */ -}}
2626
{{- $apiVersion := .APIVersion }}
2727
{{- range $referencedServiceName := .ReferencedServiceNames }}
2828
{{- if not (eq $referencedServiceName $servicePackageName) }}
29-
{{ $referencedServiceName }}apitypes "github.com/aws-controllers-k8s/{{ $referencedServiceName }}-controller/apis/{{ $apiVersion }}"
29+
{{ $referencedServiceName }}apitypes "github.com/aws-controllers-k8s/{{ $referencedServiceName }}-controller/apis/{{ $apiVersion }}"
3030
{{- end }}
3131
{{- end }}
3232
{{/* TODO(a-hilaly): import apis/* packages to register webhooks */}}
3333
{{range $crdName := .SnakeCasedCRDNames }}_ "github.com/aws-controllers-k8s/{{ $servicePackageName }}-controller/pkg/resource/{{ $crdName }}"
3434
{{end}}
35+
"github.com/aws-controllers-k8s/{{ .ServicePackageName }}-controller/pkg/version"
3536
)
3637

3738
var (
38-
awsServiceAPIGroup = "{{ .APIGroup }}"
39-
awsServiceAlias = "{{ .ServicePackageName }}"
40-
awsServiceEndpointsID = svcsdk.EndpointsID
41-
scheme = runtime.NewScheme()
42-
setupLog = ctrlrt.Log.WithName("setup")
39+
awsServiceAPIGroup = "{{ .APIGroup }}"
40+
awsServiceAlias = "{{ .ServicePackageName }}"
41+
awsServiceEndpointsID = svcsdk.EndpointsID
42+
scheme = runtime.NewScheme()
43+
setupLog = ctrlrt.Log.WithName("setup")
4344
)
4445

4546
func init() {
@@ -49,7 +50,7 @@ func init() {
4950
_ = ackv1alpha1.AddToScheme(scheme)
5051
{{- range $referencedServiceName := .ReferencedServiceNames }}
5152
{{- if not (eq $referencedServiceName $servicePackageName) }}
52-
_ = {{ $referencedServiceName }}apitypes.AddToScheme(scheme)
53+
_ = {{ $referencedServiceName }}apitypes.AddToScheme(scheme)
5354
{{- end }}
5455
{{- end }}
5556
}
@@ -78,13 +79,13 @@ func main() {
7879
}
7980

8081
mgr, err := ctrlrt.NewManager(ctrlrt.GetConfigOrDie(), ctrlrt.Options{
81-
Scheme: scheme,
82-
Port: port,
83-
Host: host,
82+
Scheme: scheme,
83+
Port: port,
84+
Host: host,
8485
MetricsBindAddress: ackCfg.MetricsAddr,
85-
LeaderElection: ackCfg.EnableLeaderElection,
86+
LeaderElection: ackCfg.EnableLeaderElection,
8687
LeaderElectionID: awsServiceAPIGroup,
87-
Namespace: ackCfg.WatchNamespace,
88+
Namespace: ackCfg.WatchNamespace,
8889
})
8990
if err != nil {
9091
setupLog.Error(
@@ -102,7 +103,11 @@ func main() {
102103
)
103104
sc := ackrt.NewServiceController(
104105
awsServiceAlias, awsServiceAPIGroup, awsServiceEndpointsID,
105-
ackrt.VersionInfo{}, // TODO: populate version info
106+
ackrt.VersionInfo{
107+
version.GitCommit,
108+
version.GitVersion,
109+
version.BuildDate,
110+
},
106111
).WithLogger(
107112
ctrlrt.Log,
108113
).WithResourceManagerFactories(

0 commit comments

Comments
 (0)