@@ -42,6 +42,11 @@ import (
42
42
// Injected during build
43
43
var version string
44
44
45
+ const (
46
+ nginxVersionAnnotation = "app.nginx.org/version"
47
+ versionAnnotation = "app.kubernetes.io/version"
48
+ )
49
+
45
50
func main () {
46
51
commitHash , commitTime , dirtyBuild := getBuildInfo ()
47
52
fmt .Printf ("NGINX Ingress Controller Version=%v Commit=%v Date=%v DirtyState=%v Arch=%v/%v Go=%v\n " , version , commitHash , commitTime , dirtyBuild , runtime .GOOS , runtime .GOARCH , runtime .Version ())
@@ -64,7 +69,9 @@ func main() {
64
69
65
70
nginxManager , useFakeNginxManager := createNginxManager (managerCollector )
66
71
67
- getNginxVersionInfo (nginxManager )
72
+ nginxVersion := getNginxVersionInfo (nginxManager )
73
+
74
+ updateSelfWithVersionInfo (kubeClient , version , nginxVersion )
68
75
69
76
templateExecutor , templateExecutorV2 := createTemplateExecutors ()
70
77
@@ -367,7 +374,7 @@ func createNginxManager(managerCollector collectors.ManagerCollector) (nginx.Man
367
374
return nginxManager , useFakeNginxManager
368
375
}
369
376
370
- func getNginxVersionInfo (nginxManager nginx.Manager ) {
377
+ func getNginxVersionInfo (nginxManager nginx.Manager ) string {
371
378
nginxVersion := nginxManager .Version ()
372
379
isPlus := strings .Contains (nginxVersion , "plus" )
373
380
glog .Infof ("Using %s" , nginxVersion )
@@ -377,6 +384,7 @@ func getNginxVersionInfo(nginxManager nginx.Manager) {
377
384
} else if ! * nginxPlus && isPlus {
378
385
glog .Fatal ("NGINX Plus binary found without NGINX Plus flag (-nginx-plus)" )
379
386
}
387
+ return nginxVersion
380
388
}
381
389
382
390
func startApAgentsAndPlugins (nginxManager nginx.Manager ) (chan error , chan error , chan error ) {
@@ -746,3 +754,29 @@ func processConfigMaps(kubeClient *kubernetes.Clientset, cfgParams *configs.Conf
746
754
}
747
755
return cfgParams
748
756
}
757
+
758
+ func updateSelfWithVersionInfo (kubeClient * kubernetes.Clientset , version string , nginxVersion string ) {
759
+ pod , err := kubeClient .CoreV1 ().Pods (os .Getenv ("POD_NAMESPACE" )).Get (context .TODO (), os .Getenv ("POD_NAME" ), meta_v1.GetOptions {})
760
+ if err != nil {
761
+ glog .Errorf ("Error getting pod: %v" , err )
762
+ return
763
+ }
764
+
765
+ // Copy pod and update the annotations.
766
+ newPod := pod .DeepCopy ()
767
+ ann := newPod .ObjectMeta .Annotations
768
+ if ann == nil {
769
+ ann = make (map [string ]string )
770
+ }
771
+ ann [nginxVersionAnnotation ] = strings .Split (nginxVersion , "/" )[1 ]
772
+ ann [versionAnnotation ] = version
773
+ newPod .ObjectMeta .Annotations = ann
774
+
775
+ _ , err = kubeClient .CoreV1 ().Pods (newPod .ObjectMeta .Namespace ).Update (context .TODO (), newPod , meta_v1.UpdateOptions {})
776
+ if err != nil {
777
+ glog .Errorf ("Error updating pod with annotations: %v" , err )
778
+ return
779
+ }
780
+
781
+ glog .Infof ("Pod annotation updated: %s" , pod .ObjectMeta .Name )
782
+ }
0 commit comments