Skip to content
Snippets Groups Projects
Commit 1ae4932e authored by Benedikt Wetzel's avatar Benedikt Wetzel
Browse files

Add addional patcher to make it possible to set matchlabels

parent 37d9dc5f
No related branches found
No related tags found
1 merge request!239Add addional patcher to make it possible to set matchlabels
Pipeline #6555 passed
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
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
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