Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions cmd/nginx-ingress/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ import (
// Injected during build
var version string

const (
nginxVersionAnnotation = "app.nginx.org/version"
versionAnnotation = "app.kubernetes.io/version"
)

func main() {
commitHash, commitTime, dirtyBuild := getBuildInfo()
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())
Expand All @@ -64,7 +69,9 @@ func main() {

nginxManager, useFakeNginxManager := createNginxManager(managerCollector)

getNginxVersionInfo(nginxManager)
nginxVersion := getNginxVersionInfo(nginxManager)

updateSelfWithVersionInfo(kubeClient, version, nginxVersion)

templateExecutor, templateExecutorV2 := createTemplateExecutors()

Expand Down Expand Up @@ -367,7 +374,7 @@ func createNginxManager(managerCollector collectors.ManagerCollector) (nginx.Man
return nginxManager, useFakeNginxManager
}

func getNginxVersionInfo(nginxManager nginx.Manager) {
func getNginxVersionInfo(nginxManager nginx.Manager) string {
nginxVersion := nginxManager.Version()
isPlus := strings.Contains(nginxVersion, "plus")
glog.Infof("Using %s", nginxVersion)
Expand All @@ -377,6 +384,7 @@ func getNginxVersionInfo(nginxManager nginx.Manager) {
} else if !*nginxPlus && isPlus {
glog.Fatal("NGINX Plus binary found without NGINX Plus flag (-nginx-plus)")
}
return nginxVersion
}

func startApAgentsAndPlugins(nginxManager nginx.Manager) (chan error, chan error, chan error) {
Expand Down Expand Up @@ -746,3 +754,29 @@ func processConfigMaps(kubeClient *kubernetes.Clientset, cfgParams *configs.Conf
}
return cfgParams
}

func updateSelfWithVersionInfo(kubeClient *kubernetes.Clientset, version string, nginxVersion string) {
pod, err := kubeClient.CoreV1().Pods(os.Getenv("POD_NAMESPACE")).Get(context.TODO(), os.Getenv("POD_NAME"), meta_v1.GetOptions{})
if err != nil {
glog.Errorf("Error getting pod: %v", err)
return
}

// Copy pod and update the annotations.
newPod := pod.DeepCopy()
ann := newPod.ObjectMeta.Annotations
if ann == nil {
ann = make(map[string]string)
}
ann[nginxVersionAnnotation] = strings.Split(nginxVersion, "/")[1]
ann[versionAnnotation] = version
newPod.ObjectMeta.Annotations = ann

_, err = kubeClient.CoreV1().Pods(newPod.ObjectMeta.Namespace).Update(context.TODO(), newPod, meta_v1.UpdateOptions{})
if err != nil {
glog.Errorf("Error updating pod with annotations: %v", err)
return
}

glog.Infof("Pod annotation updated: %s", pod.ObjectMeta.Name)
}
1 change: 1 addition & 0 deletions deployments/daemon-set/nginx-ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ spec:
metadata:
labels:
app: nginx-ingress
app.kubernetes.io/name: nginx-ingress
#annotations:
#prometheus.io/scrape: "true"
#prometheus.io/port: "9113"
Expand Down
1 change: 1 addition & 0 deletions deployments/daemon-set/nginx-plus-ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ spec:
metadata:
labels:
app: nginx-ingress
app.kubernetes.io/name: nginx-ingress
#annotations:
#prometheus.io/scrape: "true"
#prometheus.io/port: "9113"
Expand Down
1 change: 1 addition & 0 deletions deployments/deployment/nginx-ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ spec:
metadata:
labels:
app: nginx-ingress
app.kubernetes.io/name: nginx-ingress
#annotations:
#prometheus.io/scrape: "true"
#prometheus.io/port: "9113"
Expand Down
1 change: 1 addition & 0 deletions deployments/deployment/nginx-plus-ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ spec:
metadata:
labels:
app: nginx-ingress
app.kubernetes.io/name: nginx-ingress
#annotations:
#prometheus.io/scrape: "true"
#prometheus.io/port: "9113"
Expand Down
2 changes: 1 addition & 1 deletion deployments/helm-chart/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Expand the name of the chart.
Create labels
*/}}
{{- define "nginx-ingress.labels" -}}
app.kubernetes.io/name: {{ include "nginx-ingress.name" . }}
app.kubernetes.io/name: {{ .Chart.Name }}
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ spec:
metadata:
labels:
app: {{ include "nginx-ingress.appName" . }}
app.kubernetes.io/name: nginx-ingress
{{- if .Values.nginxServiceMesh.enable }}
nsm.nginx.com/daemonset: {{ default (include "nginx-ingress.name" .) .Values.controller.name }}
spiffe.io/spiffeid: "true"
Expand Down
2 changes: 2 additions & 0 deletions deployments/helm-chart/templates/controller-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ metadata:
name: {{ default (include "nginx-ingress.name" .) .Values.controller.name }}
namespace: {{ .Release.Namespace }}
labels:
app.kubernetes.io/name: nginx-ingress
{{- include "nginx-ingress.labels" . | nindent 4 }}
{{- if .Values.controller.annotations }}
annotations: {{ toYaml .Values.controller.annotations | nindent 4 }}
Expand All @@ -18,6 +19,7 @@ spec:
metadata:
labels:
app: {{ include "nginx-ingress.appName" . }}
app.kubernetes.io/name: nginx-ingress
{{- if .Values.nginxServiceMesh.enable }}
nsm.nginx.com/deployment: {{ default (include "nginx-ingress.name" .) .Values.controller.name }}
spiffe.io/spiffeid: "true"
Expand Down
2 changes: 2 additions & 0 deletions deployments/helm-chart/templates/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ rules:
resources:
- pods
verbs:
- get
- list
- watch
- update
- apiGroups:
- ""
resources:
Expand Down
2 changes: 2 additions & 0 deletions deployments/rbac/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ rules:
resources:
- pods
verbs:
- get
- list
- watch
- update
- apiGroups:
- ""
resources:
Expand Down