Skip to content

Commit c580047

Browse files
Add plugin version and image tags as annotations to the resources (#886)
``` directpv.min.io/image-tag directpv.min.io/plugin-version ``` are the annotations added to the components
1 parent 941907b commit c580047

File tree

10 files changed

+103
-48
lines changed

10 files changed

+103
-48
lines changed

cmd/kubectl-directpv/install.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,11 @@ func installMain(ctx context.Context) {
280280
os.Exit(1)
281281
}
282282

283+
pluginVersion := "dev"
284+
if Version != "" {
285+
pluginVersion = Version
286+
}
287+
283288
args.Registry = registry
284289
args.Org = org
285290
args.ImagePullSecrets = imagePullSecrets
@@ -290,6 +295,7 @@ func installMain(ctx context.Context) {
290295
args.Quiet = quietFlag
291296
args.KubeVersion = kubeVersion
292297
args.Legacy = legacyFlag
298+
args.PluginVersion = pluginVersion
293299
if file != nil {
294300
args.ObjectWriter = file
295301
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ 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"
94+
95+
// PluginVersionLabelKey denotes the plugin version
96+
PluginVersionLabelKey LabelKey = consts.GroupName + "/plugin-version"
9197
)
9298

9399
// LabelValue is a type definition for label value

pkg/installer/args.go

Lines changed: 11 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"
@@ -71,16 +72,25 @@ type Args struct {
7172
ObjectMarshaler func(runtime.Object) ([]byte, error)
7273
ProgressCh chan<- Message
7374
ForceUninstall bool
75+
PluginVersion string
7476

7577
podSecurityAdmission bool
7678
csiProvisionerImage string
7779
nodeDriverRegistrarImage string
7880
livenessProbeImage string
7981
csiResizerImage string
82+
imageTag string
8083
}
8184

85+
var imageTagRegex = regexp.MustCompile(`:([^/]+)$`)
86+
8287
// NewArgs creates arguments for DirectPV installation.
8388
func NewArgs(image string) *Args {
89+
imageTag := "dev"
90+
matchIndex := imageTagRegex.FindStringSubmatchIndex(image)
91+
if len(matchIndex) > 0 && len(image) > matchIndex[0]+1 {
92+
imageTag = image[matchIndex[0]+1:]
93+
}
8494
return &Args{
8595
image: image,
8696
Registry: "quay.io",
@@ -90,6 +100,7 @@ func NewArgs(image string) *Args {
90100
nodeDriverRegistrarImage: nodeDriverRegistrarImage,
91101
livenessProbeImage: livenessProbeImage,
92102
csiResizerImage: csiResizerImage,
103+
imageTag: imageTag,
93104
}
94105
}
95106

pkg/installer/csidriver.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"errors"
2222
"fmt"
2323

24+
directpvtypes "github.com/minio/directpv/pkg/apis/directpv.min.io/types"
2425
"github.com/minio/directpv/pkg/consts"
2526
"github.com/minio/directpv/pkg/k8s"
2627
legacyclient "github.com/minio/directpv/pkg/legacy/client"
@@ -90,10 +91,12 @@ func doCreateCSIDriver(ctx context.Context, args *Args, version string, legacy b
9091
Kind: "CSIDriver",
9192
},
9293
ObjectMeta: metav1.ObjectMeta{
93-
Name: name,
94-
Namespace: metav1.NamespaceNone,
95-
Annotations: map[string]string{},
96-
Labels: defaultLabels,
94+
Name: name,
95+
Namespace: metav1.NamespaceNone,
96+
Annotations: map[string]string{
97+
string(directpvtypes.PluginVersionLabelKey): args.PluginVersion,
98+
},
99+
Labels: defaultLabels,
97100
},
98101
Spec: storagev1.CSIDriverSpec{
99102
PodInfoOnMount: &podInfoOnMount,
@@ -121,10 +124,12 @@ func doCreateCSIDriver(ctx context.Context, args *Args, version string, legacy b
121124
Kind: "CSIDriver",
122125
},
123126
ObjectMeta: metav1.ObjectMeta{
124-
Name: name,
125-
Namespace: metav1.NamespaceNone,
126-
Annotations: map[string]string{},
127-
Labels: defaultLabels,
127+
Name: name,
128+
Namespace: metav1.NamespaceNone,
129+
Annotations: map[string]string{
130+
string(directpvtypes.PluginVersionLabelKey): args.PluginVersion,
131+
},
132+
Labels: defaultLabels,
128133
},
129134
Spec: storagev1beta1.CSIDriverSpec{
130135
PodInfoOnMount: &podInfoOnMount,

pkg/installer/daemonset.go

Lines changed: 13 additions & 9 deletions
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/consts"
2425
"github.com/minio/directpv/pkg/k8s"
2526
legacyclient "github.com/minio/directpv/pkg/legacy/client"
@@ -203,12 +204,12 @@ func livenessProbeContainer(image string) corev1.Container {
203204
}
204205
}
205206

206-
func newDaemonset(podSpec corev1.PodSpec, name, selectorValue, appArmorProfile string) *appsv1.DaemonSet {
207+
func newDaemonset(podSpec corev1.PodSpec, name, selectorValue string, args *Args) *appsv1.DaemonSet {
207208
annotations := map[string]string{createdByLabel: pluginName}
208-
if appArmorProfile != "" {
209+
if args.AppArmorProfile != "" {
209210
// AppArmor profiles need to be specified per-container
210211
for _, container := range podSpec.Containers {
211-
annotations["container.apparmor.security.beta.kubernetes.io/"+container.Name] = "localhost/" + appArmorProfile
212+
annotations["container.apparmor.security.beta.kubernetes.io/"+container.Name] = "localhost/" + args.AppArmorProfile
212213
}
213214
}
214215

@@ -218,10 +219,13 @@ func newDaemonset(podSpec corev1.PodSpec, name, selectorValue, appArmorProfile s
218219
Kind: "DaemonSet",
219220
},
220221
ObjectMeta: metav1.ObjectMeta{
221-
Name: name,
222-
Namespace: namespace,
223-
Annotations: map[string]string{},
224-
Labels: defaultLabels,
222+
Name: name,
223+
Namespace: namespace,
224+
Annotations: map[string]string{
225+
string(directpvtypes.ImageTagLabelKey): args.imageTag,
226+
string(directpvtypes.PluginVersionLabelKey): args.PluginVersion,
227+
},
228+
Labels: defaultLabels,
225229
},
226230
Spec: appsv1.DaemonSetSpec{
227231
Selector: metav1.AddLabelToSelector(&metav1.LabelSelector{}, selectorKey, selectorValue),
@@ -302,7 +306,7 @@ func doCreateDaemonset(ctx context.Context, args *Args) (err error) {
302306
selectorValue = fmt.Sprintf("%v-%v", consts.Identity, getRandSuffix())
303307
}
304308

305-
daemonset := newDaemonset(podSpec, consts.NodeServerName, selectorValue, args.AppArmorProfile)
309+
daemonset := newDaemonset(podSpec, consts.NodeServerName, selectorValue, args)
306310

307311
if !args.DryRun && !args.Declarative {
308312
_, err = k8s.KubeClient().AppsV1().DaemonSets(namespace).Create(
@@ -365,7 +369,7 @@ func doCreateLegacyDaemonset(ctx context.Context, args *Args) (err error) {
365369
selectorValue = fmt.Sprintf("%v-%v", consts.Identity, getRandSuffix())
366370
}
367371

368-
daemonset := newDaemonset(podSpec, consts.LegacyNodeServerName, selectorValue, args.AppArmorProfile)
372+
daemonset := newDaemonset(podSpec, consts.LegacyNodeServerName, selectorValue, args)
369373

370374
if !args.DryRun && !args.Declarative {
371375
_, err = k8s.KubeClient().AppsV1().DaemonSets(namespace).Create(

pkg/installer/deployment.go

Lines changed: 8 additions & 4 deletions
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/consts"
2425
"github.com/minio/directpv/pkg/k8s"
2526
appsv1 "k8s.io/api/apps/v1"
@@ -201,10 +202,13 @@ func doCreateDeployment(ctx context.Context, args *Args, legacy bool, step int)
201202
Kind: "Deployment",
202203
},
203204
ObjectMeta: metav1.ObjectMeta{
204-
Name: name,
205-
Namespace: namespace,
206-
Annotations: map[string]string{},
207-
Labels: defaultLabels,
205+
Name: name,
206+
Namespace: namespace,
207+
Annotations: map[string]string{
208+
string(directpvtypes.ImageTagLabelKey): args.imageTag,
209+
string(directpvtypes.PluginVersionLabelKey): args.PluginVersion,
210+
},
211+
Labels: defaultLabels,
208212
},
209213
Spec: appsv1.DeploymentSpec{
210214
Replicas: &replicas,

pkg/installer/namespace.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package installer
1919
import (
2020
"context"
2121

22+
directpvtypes "github.com/minio/directpv/pkg/apis/directpv.min.io/types"
2223
"github.com/minio/directpv/pkg/k8s"
2324
corev1 "k8s.io/api/core/v1"
2425
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -87,11 +88,13 @@ func createNamespace(ctx context.Context, args *Args) (err error) {
8788
Kind: "Namespace",
8889
},
8990
ObjectMeta: metav1.ObjectMeta{
90-
Name: namespace,
91-
Namespace: metav1.NamespaceNone,
92-
Annotations: map[string]string{},
93-
Labels: labels,
94-
Finalizers: []string{metav1.FinalizerDeleteDependents},
91+
Name: namespace,
92+
Namespace: metav1.NamespaceNone,
93+
Annotations: map[string]string{
94+
string(directpvtypes.PluginVersionLabelKey): args.PluginVersion,
95+
},
96+
Labels: labels,
97+
Finalizers: []string{metav1.FinalizerDeleteDependents},
9598
},
9699
}
97100

pkg/installer/psp.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"errors"
2222

23+
directpvtypes "github.com/minio/directpv/pkg/apis/directpv.min.io/types"
2324
"github.com/minio/directpv/pkg/consts"
2425
"github.com/minio/directpv/pkg/k8s"
2526
corev1 "k8s.io/api/core/v1"
@@ -87,10 +88,12 @@ func createPSPClusterRoleBinding(ctx context.Context, args *Args) (err error) {
8788
Kind: "ClusterRoleBinding",
8889
},
8990
ObjectMeta: metav1.ObjectMeta{
90-
Name: pspClusterRoleBindingName,
91-
Namespace: metav1.NamespaceNone,
92-
Annotations: map[string]string{},
93-
Labels: defaultLabels,
91+
Name: pspClusterRoleBindingName,
92+
Namespace: metav1.NamespaceNone,
93+
Annotations: map[string]string{
94+
string(directpvtypes.PluginVersionLabelKey): args.PluginVersion,
95+
},
96+
Labels: defaultLabels,
9497
},
9598
Subjects: []rbac.Subject{
9699
{
@@ -133,10 +136,12 @@ func createPodSecurityPolicy(ctx context.Context, args *Args) (err error) {
133136
Kind: "PodSecurityPolicy",
134137
},
135138
ObjectMeta: metav1.ObjectMeta{
136-
Name: consts.Identity,
137-
Namespace: metav1.NamespaceNone,
138-
Annotations: map[string]string{},
139-
Labels: defaultLabels,
139+
Name: consts.Identity,
140+
Namespace: metav1.NamespaceNone,
141+
Annotations: map[string]string{
142+
string(directpvtypes.PluginVersionLabelKey): args.PluginVersion,
143+
},
144+
Labels: defaultLabels,
140145
},
141146
Spec: policy.PodSecurityPolicySpec{
142147
Privileged: true,

pkg/installer/rbac.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package installer
1919
import (
2020
"context"
2121

22+
directpvtypes "github.com/minio/directpv/pkg/apis/directpv.min.io/types"
2223
"github.com/minio/directpv/pkg/consts"
2324
"github.com/minio/directpv/pkg/k8s"
2425
corev1 "k8s.io/api/core/v1"
@@ -94,10 +95,12 @@ func createServiceAccount(ctx context.Context, args *Args) (err error) {
9495
Kind: "ServiceAccount",
9596
},
9697
ObjectMeta: metav1.ObjectMeta{
97-
Name: consts.Identity,
98-
Namespace: namespace,
99-
Annotations: map[string]string{},
100-
Labels: defaultLabels,
98+
Name: consts.Identity,
99+
Namespace: namespace,
100+
Annotations: map[string]string{
101+
string(directpvtypes.PluginVersionLabelKey): args.PluginVersion,
102+
},
103+
Labels: defaultLabels,
101104
},
102105
Secrets: []corev1.ObjectReference{},
103106
ImagePullSecrets: []corev1.LocalObjectReference{},
@@ -137,6 +140,7 @@ func createClusterRole(ctx context.Context, args *Args) (err error) {
137140
Namespace: metav1.NamespaceNone,
138141
Annotations: map[string]string{
139142
"rbac.authorization.kubernetes.io/autoupdate": "true",
143+
string(directpvtypes.PluginVersionLabelKey): args.PluginVersion,
140144
},
141145
Labels: defaultLabels,
142146
},
@@ -203,6 +207,7 @@ func createClusterRoleBinding(ctx context.Context, args *Args) (err error) {
203207
Namespace: metav1.NamespaceNone,
204208
Annotations: map[string]string{
205209
"rbac.authorization.kubernetes.io/autoupdate": "true",
210+
string(directpvtypes.PluginVersionLabelKey): args.PluginVersion,
206211
},
207212
Labels: defaultLabels,
208213
},
@@ -253,6 +258,7 @@ func createRole(ctx context.Context, args *Args) (err error) {
253258
Namespace: namespace,
254259
Annotations: map[string]string{
255260
"rbac.authorization.kubernetes.io/autoupdate": "true",
261+
string(directpvtypes.PluginVersionLabelKey): args.PluginVersion,
256262
},
257263
Labels: defaultLabels,
258264
},
@@ -294,6 +300,7 @@ func createRoleBinding(ctx context.Context, args *Args) (err error) {
294300
Namespace: namespace,
295301
Annotations: map[string]string{
296302
"rbac.authorization.kubernetes.io/autoupdate": "true",
303+
string(directpvtypes.PluginVersionLabelKey): args.PluginVersion,
297304
},
298305
Labels: defaultLabels,
299306
},

pkg/installer/storageclass.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,13 @@ func doCreateStorageClass(ctx context.Context, args *Args, version string, legac
9999
storageClass := &storagev1.StorageClass{
100100
TypeMeta: metav1.TypeMeta{APIVersion: "storage.k8s.io/v1", Kind: "StorageClass"},
101101
ObjectMeta: metav1.ObjectMeta{
102-
Name: name,
103-
Namespace: metav1.NamespaceNone,
104-
Annotations: map[string]string{},
105-
Labels: defaultLabels,
106-
Finalizers: []string{metav1.FinalizerDeleteDependents},
102+
Name: name,
103+
Namespace: metav1.NamespaceNone,
104+
Annotations: map[string]string{
105+
string(directpvtypes.PluginVersionLabelKey): args.PluginVersion,
106+
},
107+
Labels: defaultLabels,
108+
Finalizers: []string{metav1.FinalizerDeleteDependents},
107109
},
108110
Provisioner: consts.Identity,
109111
AllowVolumeExpansion: &allowExpansion,
@@ -131,11 +133,13 @@ func doCreateStorageClass(ctx context.Context, args *Args, version string, legac
131133
storageClass := &storagev1beta1.StorageClass{
132134
TypeMeta: metav1.TypeMeta{APIVersion: "storage.k8s.io/v1beta1", Kind: "StorageClass"},
133135
ObjectMeta: metav1.ObjectMeta{
134-
Name: name,
135-
Namespace: metav1.NamespaceNone,
136-
Annotations: map[string]string{},
137-
Labels: defaultLabels,
138-
Finalizers: []string{metav1.FinalizerDeleteDependents},
136+
Name: name,
137+
Namespace: metav1.NamespaceNone,
138+
Annotations: map[string]string{
139+
string(directpvtypes.PluginVersionLabelKey): args.PluginVersion,
140+
},
141+
Labels: defaultLabels,
142+
Finalizers: []string{metav1.FinalizerDeleteDependents},
139143
},
140144
Provisioner: consts.Identity,
141145
AllowVolumeExpansion: &allowExpansion,

0 commit comments

Comments
 (0)