mirror of
https://github.com/jenkinsci/kubernetes-operator.git
synced 2026-10-20 02:38:43 +02:00
Fixed targetPort value
Made the targetPort in Jenkins pod a fixed value. Previously users encountered issue with changing values. Added test comparing expected and actual targetPort values.
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
jenkinsclient "github.com/jenkinsci/kubernetes-operator/pkg/client"
|
||||
"github.com/jenkinsci/kubernetes-operator/pkg/configuration/base"
|
||||
"github.com/jenkinsci/kubernetes-operator/pkg/configuration/base/resources"
|
||||
"github.com/jenkinsci/kubernetes-operator/pkg/constants"
|
||||
"github.com/jenkinsci/kubernetes-operator/pkg/groovy"
|
||||
"github.com/jenkinsci/kubernetes-operator/pkg/plugins"
|
||||
|
||||
@@ -20,6 +21,7 @@ import (
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
)
|
||||
|
||||
const e2e = "e2e"
|
||||
@@ -92,6 +94,7 @@ func TestConfiguration(t *testing.T) {
|
||||
createKubernetesCredentialsProviderSecret(t, namespace, mySeedJob)
|
||||
waitForJenkinsBaseConfigurationToComplete(t, jenkins)
|
||||
verifyJenkinsMasterPodAttributes(t, jenkins)
|
||||
verifyServices(t, jenkins)
|
||||
jenkinsClient, cleanUpFunc := verifyJenkinsAPIConnection(t, jenkins, namespace)
|
||||
defer cleanUpFunc()
|
||||
verifyPlugins(t, jenkinsClient, jenkins)
|
||||
@@ -370,6 +373,13 @@ if (!"%s".equals(Jenkins.instance.systemMessage)) {
|
||||
assert.NoError(t, err, logs)
|
||||
}
|
||||
|
||||
func verifyServices(t *testing.T, jenkins *v1alpha2.Jenkins) {
|
||||
jenkinsHTTPService := getJenkinsService(t, jenkins, "http")
|
||||
jenkinsSlaveService := getJenkinsService(t, jenkins, "slave")
|
||||
assert.Equal(t, intstr.IntOrString{IntVal: constants.DefaultHTTPPortInt32, Type: intstr.Int}, jenkinsHTTPService.Spec.Ports[0].TargetPort)
|
||||
assert.Equal(t, intstr.IntOrString{IntVal: constants.DefaultSlavePortInt32, Type: intstr.Int}, jenkinsSlaveService.Spec.Ports[0].TargetPort)
|
||||
}
|
||||
|
||||
func assertMapContainsElementsFromAnotherMap(t *testing.T, expected map[string]string, actual map[string]string) {
|
||||
for key, expectedValue := range expected {
|
||||
actualValue, keyExists := actual[key]
|
||||
|
||||
@@ -2,6 +2,7 @@ package e2e
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2"
|
||||
@@ -16,6 +17,7 @@ import (
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
rbacv1 "k8s.io/api/rbac/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/fields"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
@@ -236,3 +238,16 @@ func restartJenkinsMasterPod(t *testing.T, jenkins *v1alpha2.Jenkins) {
|
||||
}
|
||||
t.Log("Jenkins master pod has been restarted")
|
||||
}
|
||||
|
||||
func getJenkinsService(t *testing.T, jenkins *v1alpha2.Jenkins, serviceKind string) *corev1.Service {
|
||||
serviceName := constants.OperatorName + "-" + serviceKind + "-" + jenkins.ObjectMeta.Name
|
||||
lo := metav1.ListOptions{
|
||||
FieldSelector: fields.SelectorFromSet(fields.Set{"metadata.name": serviceName}).String(),
|
||||
}
|
||||
serviceList, err := framework.Global.KubeClient.CoreV1().Services(jenkins.Namespace).List(lo)
|
||||
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 1, len(serviceList.Items), fmt.Sprintf("'%s' service not found", serviceName))
|
||||
|
||||
return &serviceList.Items[0]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user