Skip to content

Commit 8daf729

Browse files
Add image-tag annotation to the deployment and daemonset (#965)
This PR brings back the image-tag annotation which can be used to identify the image version installer
1 parent f6f0df8 commit 8daf729

File tree

8 files changed

+59
-2
lines changed

8 files changed

+59
-2
lines changed

pkg/admin/installer/args.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"fmt"
2222
"io"
2323
"path"
24+
"regexp"
2425

2526
"github.com/minio/directpv/pkg/utils"
2627
corev1 "k8s.io/api/core/v1"
@@ -79,10 +80,18 @@ type Args struct {
7980
nodeDriverRegistrarImage string
8081
livenessProbeImage string
8182
csiResizerImage string
83+
imageTag string
8284
}
8385

86+
var imageTagRegex = regexp.MustCompile(`:([^/]+)$`)
87+
8488
// NewArgs creates arguments for DirectPV installation.
8589
func NewArgs(image string) *Args {
90+
imageTag := "dev"
91+
matchIndex := imageTagRegex.FindStringSubmatchIndex(image)
92+
if len(matchIndex) > 0 && len(image) > matchIndex[0]+1 {
93+
imageTag = image[matchIndex[0]+1:]
94+
}
8695
return &Args{
8796
image: image,
8897
Registry: "quay.io",
@@ -92,6 +101,7 @@ func NewArgs(image string) *Args {
92101
nodeDriverRegistrarImage: nodeDriverRegistrarImage,
93102
livenessProbeImage: livenessProbeImage,
94103
csiResizerImage: csiResizerImage,
104+
imageTag: imageTag,
95105
}
96106
}
97107

pkg/admin/installer/daemonset.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"fmt"
2222

23+
directpvtypes "github.com/minio/directpv/pkg/apis/directpv.min.io/types"
2324
"github.com/minio/directpv/pkg/client"
2425
"github.com/minio/directpv/pkg/consts"
2526
"github.com/minio/directpv/pkg/k8s"
@@ -214,7 +215,10 @@ func newDaemonset(podSpec corev1.PodSpec, name, selectorValue string, args *Args
214215
ObjectMeta: metav1.ObjectMeta{
215216
Name: name,
216217
Namespace: namespace,
217-
Labels: defaultLabels,
218+
Annotations: map[string]string{
219+
string(directpvtypes.ImageTagLabelKey): args.imageTag,
220+
},
221+
Labels: defaultLabels,
218222
},
219223
Spec: appsv1.DaemonSetSpec{
220224
Selector: metav1.AddLabelToSelector(&metav1.LabelSelector{}, selectorKey, selectorValue),

pkg/admin/installer/deployment.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"fmt"
2222

23+
directpvtypes "github.com/minio/directpv/pkg/apis/directpv.min.io/types"
2324
"github.com/minio/directpv/pkg/client"
2425
"github.com/minio/directpv/pkg/consts"
2526
"github.com/minio/directpv/pkg/k8s"
@@ -206,7 +207,10 @@ func (t deploymentTask) doCreateDeployment(ctx context.Context, args *Args, lega
206207
ObjectMeta: metav1.ObjectMeta{
207208
Name: name,
208209
Namespace: namespace,
209-
Labels: defaultLabels,
210+
Annotations: map[string]string{
211+
string(directpvtypes.ImageTagLabelKey): args.imageTag,
212+
},
213+
Labels: defaultLabels,
210214
},
211215
Spec: appsv1.DeploymentSpec{
212216
Replicas: &replicas,

pkg/apis/directpv.min.io/types/label.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ const (
8888

8989
// ClaimIDLabelKey label key to denote the claim id of the volumes
9090
ClaimIDLabelKey LabelKey = consts.GroupName + "/claim-id"
91+
92+
// ImageTagLabelKey denotes the tag of the directpv container image
93+
ImageTagLabelKey LabelKey = consts.GroupName + "/image-tag"
9194
)
9295

9396
var reservedLabelKeys = map[LabelKey]struct{}{
@@ -109,6 +112,7 @@ var reservedLabelKeys = map[LabelKey]struct{}{
109112
SuspendLabelKey: {},
110113
VolumeClaimIDLabelKey: {},
111114
ClaimIDLabelKey: {},
115+
ImageTagLabelKey: {},
112116
}
113117

114118
// IsReserved returns if the key is a reserved key

resources/base/DaemonSet.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ apiVersion: apps/v1
33
kind: DaemonSet
44
metadata:
55
creationTimestamp: null
6+
annotations:
7+
directpv.min.io/image-tag: v4.1.4
68
labels:
79
application-name: directpv.min.io
810
application-type: CSIDriver

resources/base/Deployment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ apiVersion: apps/v1
33
kind: Deployment
44
metadata:
55
creationTimestamp: null
6+
annotations:
7+
directpv.min.io/image-tag: v4.1.4
68
labels:
79
application-name: directpv.min.io
810
application-type: CSIDriver

resources/base/kustomization.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,18 @@ images:
3333
- name: quay.io/minio/csi-resizer
3434
digest: sha256:58fa627393f20892b105a137d27e236dfaec233a3a64980f84dcb15f38c21533
3535

36+
patches:
37+
- patch: |-
38+
- op: replace
39+
path: /metadata/annotations/directpv.min.io~1image-tag
40+
value: v4.1.4
41+
target:
42+
kind: Deployment
43+
name: controller
44+
- patch: |-
45+
- op: replace
46+
path: /metadata/annotations/directpv.min.io~1image-tag
47+
value: v4.1.4
48+
target:
49+
kind: DaemonSet
50+
name: node-server

resources/v4.0/base/kustomization.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,19 @@ resources:
88
images:
99
- name: quay.io/minio/directpv
1010
digest: sha256:98c23183f3abb8d9b6e0c300677605cc822e039fc81ce0e5dd8bef1006547627
11+
12+
patches:
13+
- patch: |-
14+
- op: replace
15+
path: /metadata/annotations/directpv.min.io~1image-tag
16+
value: v4.0.16
17+
target:
18+
kind: Deployment
19+
name: controller
20+
- patch: |-
21+
- op: replace
22+
path: /metadata/annotations/directpv.min.io~1image-tag
23+
value: v4.0.16
24+
target:
25+
kind: DaemonSet
26+
name: node-server

0 commit comments

Comments
 (0)