Skip to content
Snippets Groups Projects
Commit 4ebf56d3 authored by Sören Henning's avatar Sören Henning
Browse files

Merge branch 'add-match-label-patcher' into 'master'

Add addional patcher to make it possible to set matchlabels

See merge request !239
parents 37d9dc5f 1632d14f
No related branches found
No related tags found
1 merge request!239Add addional patcher to make it possible to set matchlabels
Pipeline #6558 passed
......@@ -53,6 +53,27 @@ Patchers can be seen as functions which take a value as input and modify a Kuber
* **resource**: "uc1-kstreams-deployment.yaml"
* **example value**: "random-scheduler"
* **LabelPatcher**: Changes the label of a Kubernetes Deployment or StatefulSet. The patched field is: `metadata.labels`
* **type**: "LabelPatcher"
* **resource**: "uc1-kstreams-deployment.yaml"
* **properties**:
* variableName: "app"
* **example value**: "theodolite-sut"
* **MatchLabelPatcher**: Changes the match labels of a Kubernetes Deployment or StatefulSet. The patched field is: `spec.selector.matchLabels`
* **type**: "MatchLabelPatcher"
* **resource**: "uc1-kstreams-deployment.yaml"
* **properties**:
* variableName: "app"
* **example value**: "theodolite-sut"
* **TemplateLabelPatcher**: Changes the template labels of a Kubernetes Deployment or StatefulSet. The patched field is: `spec.template.metadata.labels`
* **type**: "MatchLabelPatcher"
* **resource**: "uc1-kstreams-deployment.yaml"
* **properties**:
* variableName: "app"
* **example value**: "theodolite-sut"
* **ImagePatcher**: Changes the image of a Kubernetes resource. **Currently not fully implemented.**
* **type**: "ImagePatcher"
* **resource**: "uc1-kstreams-deployment.yaml"
......
package theodolite.patcher
import io.fabric8.kubernetes.api.model.KubernetesResource
import io.fabric8.kubernetes.api.model.apps.Deployment
import io.fabric8.kubernetes.api.model.apps.StatefulSet
/**
* This patcher is able to set the `spec.selector.matchLabels` for a `Deployment` or `StatefulSet` Kubernetes resource.
*
* @property k8sResource The Kubernetes manifests to patch
* @property variableName The matchLabel which should be set
*/
class MatchLabelPatcher(private val k8sResource: KubernetesResource, val variableName: String) :
AbstractPatcher(k8sResource) {
override fun <String> patch(labelValue: String) {
if (labelValue is kotlin.String) {
when (k8sResource) {
is Deployment -> {
if (k8sResource.spec.selector.matchLabels == null) {
k8sResource.spec.selector.matchLabels = mutableMapOf()
}
k8sResource.spec.selector.matchLabels[this.variableName] = labelValue
}
is StatefulSet -> {
if (k8sResource.spec.selector.matchLabels == null) {
k8sResource.spec.selector.matchLabels = mutableMapOf()
}
k8sResource.spec.selector.matchLabels[this.variableName] = labelValue
}
}
}
}
}
\ No newline at end of file
......@@ -79,6 +79,14 @@ class PatcherFactory {
k8sResource = resource,
variableName = patcherDefinition.properties["variableName"]!!
)
"MatchLabelPatcher" -> MatchLabelPatcher(
k8sResource = resource,
variableName = patcherDefinition.properties["variableName"]!!
)
"TemplateLabelPatcher" -> TemplateLabelPatcher(
k8sResource = resource,
variableName = patcherDefinition.properties["variableName"]!!
)
"ImagePatcher" -> ImagePatcher(
k8sResource = resource,
container = patcherDefinition.properties["container"]!!
......
package theodolite.patcher
import io.fabric8.kubernetes.api.model.KubernetesResource
import io.fabric8.kubernetes.api.model.apps.Deployment
import io.fabric8.kubernetes.api.model.apps.StatefulSet
/**
* This patcher is able to set the field `spec.template.metadata.labels` for a `Deployment` or `StatefulSet` Kubernetes resource.
*
* @property k8sResource The Kubernetes manifests to patch
* @property variableName The label which should be set
*/
class TemplateLabelPatcher(private val k8sResource: KubernetesResource, val variableName: String) :
AbstractPatcher(k8sResource) {
override fun <String> patch(labelValue: String) {
if (labelValue is kotlin.String) {
when (k8sResource) {
is Deployment -> {
if (k8sResource.spec.template.metadata.labels == null) {
k8sResource.spec.template.metadata.labels = mutableMapOf()
}
k8sResource.spec.template.metadata.labels[this.variableName] = labelValue
}
is StatefulSet -> {
if (k8sResource.spec.template.metadata.labels == null) {
k8sResource.spec.template.metadata.labels = mutableMapOf()
}
k8sResource.spec.template.metadata.labels[this.variableName] = labelValue
}
}
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment