Skip to content

Commit

Permalink
feat (jkube-kit/enricher) : VolumePermissionEnricher : Use `.spec.sto…
Browse files Browse the repository at this point in the history
…rageClassName` instead of annotation to set PersistentVolume class (eclipse-jkube#1361)

VolumePermissionEnricher should now add StorageClass name in
`.spec.storageClassName` field instead of an annotation in metadata.

Add a new configuration field `useStorageClassAnnotation` in VolumePermissionEnricher
configuration for backward compatibility. User can switch back to
annotation by setting this field to `true`.

Signed-off-by: Rohan Kumar <rohaan@redhat.com>
  • Loading branch information
rohanKanojia authored and manusa committed Jul 25, 2022
1 parent 9c076a1 commit 8123b4d
Show file tree
Hide file tree
Showing 11 changed files with 364 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Usage:
### 1.9.0-SNAPSHOT
* Fix #777: `k8s:build` with Dockerfile throws `Connection reset by peer` error on old docker daemons
* Fix #1279: Remove redundant log messages regarding plugin modes
* Fix #1361: VolumePermissionEnricher : Use `.spec.storageClassName` instead of annotation to set PersistentVolume class
* Fix #1411: Add support for adding additional ImageStreamTags in OpenShift S2I builds
* Fix #1438: Add configuration option in ServiceAccountEnricher to skip creating ServiceAccounts
* Fix #1464: Bump Fabric8 Kubernetes Client to 6.0.0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
---
apiVersion: v1
kind: List
items:
- apiVersion: v1
kind: Service
metadata:
annotations:
jkube.io/iconUrl: "@ignore@"
jkube.io/git-url: "@ignore@"
jkube.io/git-commit: "@ignore@"
jkube.io/git-branch: "@ignore@"
labels:
app: volume-permission
provider: jkube
version: "@ignore@"
expose: "true"
group: org.eclipse.jkube.devops.apps
name: jkube-docker-registry
spec:
ports:
- port: 80
protocol: TCP
targetPort: 5000
selector:
app: jkube-docker-registry
provider: jkube
group: org.eclipse.jkube.devops.apps
- apiVersion: v1
kind: PersistentVolumeClaim
metadata:
annotations:
volume.beta.kubernetes.io/storage-class: cheese
labels:
app: volume-permission
provider: jkube
version: "@ignore@"
group: org.eclipse.jkube.integration.tests.gradle
name: jkube-docker-registry-storage
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
- apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
jkube.io/iconUrl: https://cdn.rawgit.com/jkubeio/jkube-devops/master/jkube-docker-registry/src/main/jkube/icon.png
labels:
app: volume-permission
provider: jkube
version: "@ignore@"
group: org.eclipse.jkube.devops.apps
name: jkube-docker-registry
spec:
replicas: 1
revisionHistoryLimit: 2
selector:
matchLabels:
provider: jkube
app: volume-permission
group: org.eclipse.jkube.devops.apps
template:
metadata:
labels:
app: volume-permission
provider: jkube
version: "@ignore@"
group: org.eclipse.jkube.devops.apps
name: volume-permission
spec:
containers:
- env:
- name: KUBERNETES_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: HOSTNAME
valueFrom:
fieldRef:
fieldPath: metadata.name
image: registry:2
imagePullPolicy: IfNotPresent
name: jkube-docker-registry
ports:
- containerPort: 5000
name: http
resources:
limits:
cpu: "0"
memory: "0"
requests:
cpu: "0"
memory: "0"
securityContext:
privileged: false
volumeMounts:
- mountPath: /var/lib/registry
name: jkube-docker-registry-storage
readOnly: false
initContainers:
- command:
- chmod
- "777"
- /var/lib/registry
image: busybox
imagePullPolicy: IfNotPresent
name: jkube-volume-permission
volumeMounts:
- mountPath: /var/lib/registry
name: jkube-docker-registry-storage
volumes:
- name: jkube-docker-registry-storage
persistentVolumeClaim:
claimName: jkube-docker-registry-storage
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
---
apiVersion: v1
kind: List
items:
- apiVersion: v1
kind: Service
metadata:
annotations:
app.openshift.io/vcs-ref: "@ignore@"
jkube.io/git-branch: "@ignore@"
jkube.io/iconUrl: https://cdn.rawgit.com/jkubeio/jkube-devops/master/jkube-docker-registry/src/main/jkube/icon.png
jkube.io/git-url: "@ignore@"
app.openshift.io/vcs-uri: "@ignore@"
jkube.io/git-commit: "@ignore@"
labels:
app: volume-permission
provider: jkube
version: "@ignore@"
expose: "true"
group: org.eclipse.jkube.devops.apps
name: jkube-docker-registry
spec:
ports:
- port: 80
protocol: TCP
targetPort: 5000
selector:
app: jkube-docker-registry
provider: jkube
group: org.eclipse.jkube.devops.apps
- apiVersion: v1
kind: PersistentVolumeClaim
metadata:
annotations:
volume.beta.kubernetes.io/storage-class: cheese
labels:
app: volume-permission
provider: jkube
version: "@ignore@"
group: org.eclipse.jkube.integration.tests.gradle
name: jkube-docker-registry-storage
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
- apiVersion: apps.openshift.io/v1
kind: DeploymentConfig
metadata:
annotations:
jkube.io/iconUrl: https://cdn.rawgit.com/jkubeio/jkube-devops/master/jkube-docker-registry/src/main/jkube/icon.png
labels:
app: volume-permission
provider: jkube
version: "@ignore@"
group: org.eclipse.jkube.devops.apps
name: jkube-docker-registry
spec:
replicas: 1
revisionHistoryLimit: 2
selector:
provider: jkube
app: volume-permission
group: org.eclipse.jkube.devops.apps
strategy:
rollingParams:
timeoutSeconds: 3600
type: Rolling
template:
metadata:
annotations:
jkube.io/iconUrl: https://cdn.rawgit.com/jkubeio/jkube-devops/master/jkube-docker-registry/src/main/jkube/icon.png
labels:
app: volume-permission
provider: jkube
version: "@ignore@"
group: org.eclipse.jkube.devops.apps
name: volume-permission
spec:
containers:
- env:
- name: KUBERNETES_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
image: registry:2
imagePullPolicy: IfNotPresent
name: jkube-docker-registry
ports:
- containerPort: 5000
name: http
resources:
limits:
cpu: "0"
memory: "0"
requests:
cpu: "0"
memory: "0"
securityContext:
privileged: false
volumeMounts:
- mountPath: /var/lib/registry
name: jkube-docker-registry-storage
readOnly: false
initContainers:
- command:
- chmod
- "777"
- /var/lib/registry
image: busybox
imagePullPolicy: IfNotPresent
name: jkube-volume-permission
volumeMounts:
- mountPath: /var/lib/registry
name: jkube-docker-registry-storage
volumes:
- name: jkube-docker-registry-storage
persistentVolumeClaim:
claimName: jkube-docker-registry-storage
triggers:
- type: ConfigChange
- imageChangeParams:
automatic: true
containerNames:
- jkube-docker-registry
from:
kind: ImageStreamTag
name: registry:2
type: ImageChange
- apiVersion: route.openshift.io/v1
kind: Route
metadata:
annotations:
app.openshift.io/vcs-ref: "@ignore@"
jkube.io/git-branch: "@ignore@"
jkube.io/iconUrl: https://cdn.rawgit.com/jkubeio/jkube-devops/master/jkube-docker-registry/src/main/jkube/icon.png
jkube.io/git-url: "@ignore@"
app.openshift.io/vcs-uri: "@ignore@"
jkube.io/git-commit: "@ignore@"
labels:
app: volume-permission
provider: jkube
version: "@ignore@"
group: org.eclipse.jkube.devops.apps
name: jkube-docker-registry
spec:
port:
targetPort: 80
to:
kind: Service
name: jkube-docker-registry
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,14 @@ items:
- apiVersion: v1
kind: PersistentVolumeClaim
metadata:
annotations:
volume.beta.kubernetes.io/storage-class: cheese
labels:
app: volume-permission
provider: jkube
version: "@ignore@"
group: org.eclipse.jkube.integration.tests.gradle
name: jkube-docker-registry-storage
spec:
storageClassName: cheese
accessModes:
- ReadWriteOnce
resources:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,14 @@ items:
- apiVersion: v1
kind: PersistentVolumeClaim
metadata:
annotations:
volume.beta.kubernetes.io/storage-class: cheese
labels:
app: volume-permission
provider: jkube
version: "@ignore@"
group: org.eclipse.jkube.integration.tests.gradle
name: jkube-docker-registry-storage
spec:
storageClassName: cheese
accessModes:
- ReadWriteOnce
resources:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
import org.junit.runners.Parameterized;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;

Expand All @@ -35,23 +37,26 @@ public class VolumePermissionIT {
@Parameterized.Parameters(name = "{0} : jkube.enricher.jkube-volume-permission.defaultStorageClass={1}")
public static Collection<Object[]> data() {
return Arrays.asList(
new Object[] { "default", ""},
new Object[] { "custom-storageclass", "cheese"}
new Object[] { "default", new String[] {}},
new Object[] { "custom-storageclass-annotation", new String[] {"-Pjkube.enricher.jkube-volume-permission.defaultStorageClass=cheese", "-Pjkube.enricher.jkube-volume-permission.useStorageClassAnnotation=true"}},
new Object[] { "custom-storageclass", new String[] {"-Pjkube.enricher.jkube-volume-permission.defaultStorageClass=cheese"}}
);
}

@Parameterized.Parameter
public String expectedDirectory;

@Parameterized.Parameter (1)
public String defaultStorageClassEnricherConfig;
public String[] arguments;

@Test
public void k8sResourceTask_whenRun_generatesK8sManifestWithPersistentVolume() throws IOException, ParseException {
// When
List<String> gradleArgs = new ArrayList<>(Arrays.asList(arguments));
gradleArgs.add("k8sResource");
gradleArgs.add("--stacktrace");
final BuildResult result = gradleRunner.withITProject("volume-permission")
.withArguments("-Pjkube.enricher.jkube-volume-permission.defaultStorageClass=" + defaultStorageClassEnricherConfig,
"k8sResource")
.withArguments(gradleArgs.toArray(new String[0]))
.build();
// Then
ResourceVerify.verifyResourceDescriptors(gradleRunner.resolveDefaultKubernetesResourceFile(),
Expand All @@ -65,9 +70,11 @@ public void k8sResourceTask_whenRun_generatesK8sManifestWithPersistentVolume() t
@Test
public void ocResourceTask_whenRun_generatesOpenShiftManifestWithPersistentVolume() throws IOException, ParseException {
// When
List<String> gradleArgs = new ArrayList<>(Arrays.asList(arguments));
gradleArgs.add("ocResource");
gradleArgs.add("--stacktrace");
final BuildResult result = gradleRunner.withITProject("volume-permission")
.withArguments("-Pjkube.enricher.jkube-volume-permission.defaultStorageClass=" + defaultStorageClassEnricherConfig,
"ocResource")
.withArguments(gradleArgs.toArray(new String[0]))
.build();
// Then
ResourceVerify.verifyResourceDescriptors(gradleRunner.resolveDefaultOpenShiftResourceFile(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,10 @@ Defaults to `777`.
| *defaultStorageClass*
| PersistentVolume storage class.
| `jkube.enricher.jkube-volume-permission.defaultStorageClass`

| *useStorageClassAnnotation*
| If enabled, storage class would be added to PersistentVolumeClaim metadata as `volume.beta.kubernetes.io/storage-class=<storageClassName>` annotation rather than `.spec.storageClassName`

Defaults to `false`
| `jkube.enricher.jkube-volume-permission.useStorageClassAnnotation`
|===
Loading

0 comments on commit 8123b4d

Please sign in to comment.