#262 Allow configure Jenkins master pod labels
This commit is contained in:
parent
f50cf309cf
commit
be41ef44a8
|
|
@ -269,6 +269,13 @@ type JenkinsMaster struct {
|
||||||
// +optional
|
// +optional
|
||||||
AnnotationsDeprecated map[string]string `json:"masterAnnotations,omitempty"`
|
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.
|
// 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.
|
// 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/
|
// More info: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/
|
||||||
|
|
|
||||||
|
|
@ -303,6 +303,13 @@ func (in *JenkinsMaster) DeepCopyInto(out *JenkinsMaster) {
|
||||||
(*out)[key] = val
|
(*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 {
|
if in.NodeSelector != nil {
|
||||||
in, out := &in.NodeSelector, &out.NodeSelector
|
in, out := &in.NodeSelector, &out.NodeSelector
|
||||||
*out = make(map[string]string, len(*in))
|
*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))
|
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) {
|
if !compareMap(r.Configuration.Jenkins.Spec.Master.Annotations, currentJenkinsMasterPod.ObjectMeta.Annotations) {
|
||||||
messages = append(messages, "Jenkins pod annotations have changed")
|
messages = append(messages, "Jenkins pod annotations have changed")
|
||||||
verbose = append(verbose, fmt.Sprintf("Jenkins pod annotations have changed, actual '%+v' required '%+v'",
|
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)
|
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
|
// NewJenkinsMasterPod builds Jenkins Master Kubernetes Pod resource
|
||||||
func NewJenkinsMasterPod(objectMeta metav1.ObjectMeta, jenkins *v1alpha2.Jenkins) *corev1.Pod {
|
func NewJenkinsMasterPod(objectMeta metav1.ObjectMeta, jenkins *v1alpha2.Jenkins) *corev1.Pod {
|
||||||
serviceAccountName := objectMeta.Name
|
serviceAccountName := objectMeta.Name
|
||||||
objectMeta.Annotations = jenkins.Spec.Master.Annotations
|
objectMeta.Annotations = jenkins.Spec.Master.Annotations
|
||||||
objectMeta.Name = GetJenkinsMasterPodName(*jenkins)
|
objectMeta.Name = GetJenkinsMasterPodName(*jenkins)
|
||||||
|
objectMeta.Labels = GetJenkinsMasterPodLabels(*jenkins)
|
||||||
|
|
||||||
return &corev1.Pod{
|
return &corev1.Pod{
|
||||||
TypeMeta: buildPodTypeMeta(),
|
TypeMeta: buildPodTypeMeta(),
|
||||||
|
|
|
||||||
|
|
@ -227,6 +227,8 @@ func verifyJenkinsMasterPodAttributes(t *testing.T, jenkins *v1alpha2.Jenkins) {
|
||||||
|
|
||||||
assert.Equal(t, jenkins.Spec.Master.ImagePullSecrets, jenkinsPod.Spec.ImagePullSecrets)
|
assert.Equal(t, jenkins.Spec.Master.ImagePullSecrets, jenkinsPod.Spec.ImagePullSecrets)
|
||||||
|
|
||||||
|
assert.Equal(t, resources.GetJenkinsMasterPodLabels(*jenkins), jenkinsPod.Labels)
|
||||||
|
|
||||||
for _, actualContainer := range jenkinsPod.Spec.Containers {
|
for _, actualContainer := range jenkinsPod.Spec.Containers {
|
||||||
if actualContainer.Name == resources.JenkinsMasterContainerName {
|
if actualContainer.Name == resources.JenkinsMasterContainerName {
|
||||||
verifyContainer(t, resources.NewJenkinsMasterContainer(jenkins), actualContainer)
|
verifyContainer(t, resources.NewJenkinsMasterContainer(jenkins), actualContainer)
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ func getJenkins(t *testing.T, namespace, name string) *v1alpha2.Jenkins {
|
||||||
|
|
||||||
func getJenkinsMasterPod(t *testing.T, jenkins *v1alpha2.Jenkins) *corev1.Pod {
|
func getJenkinsMasterPod(t *testing.T, jenkins *v1alpha2.Jenkins) *corev1.Pod {
|
||||||
lo := metav1.ListOptions{
|
lo := metav1.ListOptions{
|
||||||
LabelSelector: labels.SelectorFromSet(resources.BuildResourceLabels(jenkins)).String(),
|
LabelSelector: labels.SelectorFromSet(resources.GetJenkinsMasterPodLabels(*jenkins)).String(),
|
||||||
}
|
}
|
||||||
podList, err := framework.Global.KubeClient.CoreV1().Pods(jenkins.ObjectMeta.Namespace).List(lo)
|
podList, err := framework.Global.KubeClient.CoreV1().Pods(jenkins.ObjectMeta.Namespace).List(lo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ func waitForJenkinsBaseConfigurationToComplete(t *testing.T, jenkins *v1alpha2.J
|
||||||
func waitForRecreateJenkinsMasterPod(t *testing.T, jenkins *v1alpha2.Jenkins) {
|
func waitForRecreateJenkinsMasterPod(t *testing.T, jenkins *v1alpha2.Jenkins) {
|
||||||
err := wait.Poll(retryInterval, 30*retryInterval, func() (bool, error) {
|
err := wait.Poll(retryInterval, 30*retryInterval, func() (bool, error) {
|
||||||
lo := metav1.ListOptions{
|
lo := metav1.ListOptions{
|
||||||
LabelSelector: labels.SelectorFromSet(resources.BuildResourceLabels(jenkins)).String(),
|
LabelSelector: labels.SelectorFromSet(resources.GetJenkinsMasterPodLabels(*jenkins)).String(),
|
||||||
}
|
}
|
||||||
podList, err := framework.Global.KubeClient.CoreV1().Pods(jenkins.ObjectMeta.Namespace).List(lo)
|
podList, err := framework.Global.KubeClient.CoreV1().Pods(jenkins.ObjectMeta.Namespace).List(lo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue