mirror of
https://github.com/jenkinsci/kubernetes-operator.git
synced 2026-10-10 09:55:31 +02:00
#262 Allow configure Jenkins master pod labels
This commit is contained in:
@@ -269,6 +269,13 @@ type JenkinsMaster struct {
|
||||
// +optional
|
||||
AnnotationsDeprecated map[string]string `json:"masterAnnotations,omitempty"`
|
||||
|
||||
// Map of string keys and values that can be used to organize and categorize
|
||||
// (scope and select) objects. May match selectors of replication controllers
|
||||
// and services.
|
||||
// More info: http://kubernetes.io/docs/user-guide/labels
|
||||
// +optional
|
||||
Labels map[string]string `json:"labels,omitempty"`
|
||||
|
||||
// NodeSelector is a selector which must be true for the pod to fit on a node.
|
||||
// Selector which must match a node's labels for the pod to be scheduled on that node.
|
||||
// More info: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/
|
||||
|
||||
@@ -303,6 +303,13 @@ func (in *JenkinsMaster) DeepCopyInto(out *JenkinsMaster) {
|
||||
(*out)[key] = val
|
||||
}
|
||||
}
|
||||
if in.Labels != nil {
|
||||
in, out := &in.Labels, &out.Labels
|
||||
*out = make(map[string]string, len(*in))
|
||||
for key, val := range *in {
|
||||
(*out)[key] = val
|
||||
}
|
||||
}
|
||||
if in.NodeSelector != nil {
|
||||
in, out := &in.NodeSelector, &out.NodeSelector
|
||||
*out = make(map[string]string, len(*in))
|
||||
|
||||
@@ -621,6 +621,12 @@ func (r *ReconcileJenkinsBaseConfiguration) checkForPodRecreation(currentJenkins
|
||||
currentJenkinsMasterPod.Spec.NodeSelector, r.Configuration.Jenkins.Spec.Master.NodeSelector))
|
||||
}
|
||||
|
||||
if !compareMap(r.Configuration.Jenkins.Spec.Master.Labels, currentJenkinsMasterPod.Labels) {
|
||||
messages = append(messages, "Jenkins pod labels have changed")
|
||||
verbose = append(verbose, fmt.Sprintf("Jenkins pod labels have changed, actual '%+v' required '%+v'",
|
||||
currentJenkinsMasterPod.Labels, r.Configuration.Jenkins.Spec.Master.Labels))
|
||||
}
|
||||
|
||||
if !compareMap(r.Configuration.Jenkins.Spec.Master.Annotations, currentJenkinsMasterPod.ObjectMeta.Annotations) {
|
||||
messages = append(messages, "Jenkins pod annotations have changed")
|
||||
verbose = append(verbose, fmt.Sprintf("Jenkins pod annotations have changed, actual '%+v' required '%+v'",
|
||||
|
||||
@@ -295,11 +295,26 @@ func GetJenkinsMasterPodName(jenkins v1alpha2.Jenkins) string {
|
||||
return fmt.Sprintf("jenkins-%s", jenkins.Name)
|
||||
}
|
||||
|
||||
// GetJenkinsMasterPodLabels returns Jenkins pod labels for given CR
|
||||
func GetJenkinsMasterPodLabels(jenkins v1alpha2.Jenkins) map[string]string {
|
||||
var labels map[string]string
|
||||
if jenkins.Spec.Master.Labels == nil {
|
||||
labels = map[string]string{}
|
||||
} else {
|
||||
labels = jenkins.Spec.Master.Labels
|
||||
}
|
||||
for key, value := range BuildResourceLabels(&jenkins) {
|
||||
labels[key] = value
|
||||
}
|
||||
return labels
|
||||
}
|
||||
|
||||
// NewJenkinsMasterPod builds Jenkins Master Kubernetes Pod resource
|
||||
func NewJenkinsMasterPod(objectMeta metav1.ObjectMeta, jenkins *v1alpha2.Jenkins) *corev1.Pod {
|
||||
serviceAccountName := objectMeta.Name
|
||||
objectMeta.Annotations = jenkins.Spec.Master.Annotations
|
||||
objectMeta.Name = GetJenkinsMasterPodName(*jenkins)
|
||||
objectMeta.Labels = GetJenkinsMasterPodLabels(*jenkins)
|
||||
|
||||
return &corev1.Pod{
|
||||
TypeMeta: buildPodTypeMeta(),
|
||||
|
||||
Reference in New Issue
Block a user