Use v1alpha2 Jenkins schema

This commit is contained in:
Tomasz Sęk 2019-06-10 17:55:09 +02:00
parent a835c64524
commit 8178e2315e
No known key found for this signature in database
GPG Key ID: DC356D23F6A644D0
38 changed files with 362 additions and 311 deletions

View File

@ -156,7 +156,7 @@ ifeq ($(ENVIRONMENT),minikube)
endif endif
@RUNNING_TESTS=1 go test -parallel=1 "./test/e2e/" -tags "$(BUILDTAGS) cgo" -v -timeout 30m -run "$(E2E_TEST_SELECTOR)" \ @RUNNING_TESTS=1 go test -parallel=1 "./test/e2e/" -tags "$(BUILDTAGS) cgo" -v -timeout 30m -run "$(E2E_TEST_SELECTOR)" \
-root=$(CURRENT_DIRECTORY) -kubeconfig=$(HOME)/.kube/config -globalMan deploy/crds/jenkins_v1alpha1_jenkins_crd.yaml -namespacedMan deploy/namespace-init.yaml $(EXTRA_ARGS) -root=$(CURRENT_DIRECTORY) -kubeconfig=$(HOME)/.kube/config -globalMan deploy/crds/jenkins_v1alpha2_jenkins_crd.yaml -namespacedMan deploy/namespace-init.yaml $(EXTRA_ARGS)
.PHONY: vet .PHONY: vet
vet: ## Verifies `go vet` passes vet: ## Verifies `go vet` passes
@ -307,7 +307,7 @@ minikube-run: export OPERATOR_NAME = $(NAME)
minikube-run: start-minikube ## Run the operator locally and use minikube as Kubernetes cluster, you can use EXTRA_ARGS minikube-run: start-minikube ## Run the operator locally and use minikube as Kubernetes cluster, you can use EXTRA_ARGS
@echo "+ $@" @echo "+ $@"
kubectl config use-context minikube kubectl config use-context minikube
kubectl apply -f deploy/crds/jenkins_v1alpha1_jenkins_crd.yaml kubectl apply -f deploy/crds/jenkins_v1alpha2_jenkins_crd.yaml
@echo "Watching '$(WATCH_NAMESPACE)' namespace" @echo "Watching '$(WATCH_NAMESPACE)' namespace"
build/_output/bin/jenkins-operator $(EXTRA_ARGS) build/_output/bin/jenkins-operator $(EXTRA_ARGS)
@ -348,7 +348,7 @@ help:
@grep -Eh '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' @grep -Eh '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: status .PHONY: status
status: ## Shows git and dep status status: ## Shows git status
@echo "+ $@" @echo "+ $@"
@echo "Commit: $(GITCOMMIT), VERSION: $(VERSION)" @echo "Commit: $(GITCOMMIT), VERSION: $(VERSION)"
@echo @echo

View File

@ -4,7 +4,7 @@ PKG=github.com/jenkinsci/kubernetes-operator
DOCKER_ORGANIZATION=virtuslab DOCKER_ORGANIZATION=virtuslab
DOCKER_REGISTRY=jenkins-operator DOCKER_REGISTRY=jenkins-operator
NAMESPACE=default NAMESPACE=default
API_VERSION=jenkins:v1alpha1 API_VERSION=jenkins:v1alpha2
MINIKUBE_KUBERNETES_VERSION=v1.12.9 MINIKUBE_KUBERNETES_VERSION=v1.12.9
MINIKUBE_DRIVER=virtualbox MINIKUBE_DRIVER=virtualbox
ENVIRONMENT=minikube ENVIRONMENT=minikube

View File

@ -0,0 +1,32 @@
apiVersion: jenkins.io/v1alpha2
kind: Jenkins
metadata:
name: example
spec:
master:
readinessProbe:
httpGet:
path: /login
port: 8080
scheme: HTTP
failureThreshold: 10
initialDelaySeconds: 30
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 5
livenessProbe:
httpGet:
path: /login
port: 8080
scheme: HTTP
initialDelaySeconds: 35
failureThreshold: 10
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 5
seedJobs:
- id: jenkins-operator
targets: "cicd/jobs/*.jenkins"
description: "Jenkins Operator repository"
repositoryBranch: master
repositoryUrl: https://github.com/jenkinsci/kubernetes-operator.git

View File

@ -0,0 +1,19 @@
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: jenkins.jenkins.io
spec:
group: jenkins.io
names:
kind: Jenkins
listKind: JenkinsList
plural: jenkins
singular: jenkins
scope: Namespaced
versions:
- name : v1alpha2
served: true
storage: true
- name : v1alpha1
served: true
storage: false

View File

@ -17,7 +17,7 @@ mkdir -p $GOPATH/src/github.com/jenkinsci
cd $GOPATH/src/github.com/jenkinsci/ cd $GOPATH/src/github.com/jenkinsci/
git clone git@github.com:jenkinsci/kubernetes-operator.git git clone git@github.com:jenkinsci/kubernetes-operator.git
cd kubernetes-operator cd kubernetes-operator
make dep make go-dependencies
``` ```
## Build and run ## Build and run
@ -31,7 +31,7 @@ make build && make minikube-run EXTRA_ARGS='--minikube --local'
Once minikube and **jenkins-operator** are up and running, apply Jenkins custom resource: Once minikube and **jenkins-operator** are up and running, apply Jenkins custom resource:
```bash ```bash
kubectl apply -f deploy/crds/jenkins_v1alpha1_jenkins_cr.yaml kubectl apply -f deploy/crds/jenkins_v1alpha2_jenkins_cr.yaml
kubectl get jenkins -o yaml kubectl get jenkins -o yaml
kubectl get po kubectl get po
``` ```
@ -68,7 +68,7 @@ To be able to work with the docker daemon on `minikube` machine run the followin
eval $(minikube docker-env) eval $(minikube docker-env)
``` ```
### When `pkg/apis/jenkinsio/v1alpha1/jenkins_types.go` has changed ### When `pkg/apis/jenkinsio/*/jenkins_types.go` has changed
Run: Run:

View File

@ -20,7 +20,7 @@ Once jenkins-operator is up and running let's deploy actual Jenkins instance.
Create manifest ie. **jenkins_instance.yaml** with following data and save it on drive. Create manifest ie. **jenkins_instance.yaml** with following data and save it on drive.
```bash ```bash
apiVersion: jenkins.io/v1alpha1 apiVersion: jenkins.io/v1alpha2
kind: Jenkins kind: Jenkins
metadata: metadata:
name: example name: example
@ -173,7 +173,7 @@ podTemplate(label: label,
Jenkins Seed Jobs are configured using `Jenkins.spec.seedJobs` section from your custom resource manifest: Jenkins Seed Jobs are configured using `Jenkins.spec.seedJobs` section from your custom resource manifest:
``` ```
apiVersion: jenkins.io/v1alpha1 apiVersion: jenkins.io/v1alpha2
kind: Jenkins kind: Jenkins
metadata: metadata:
name: example name: example
@ -205,7 +205,7 @@ If your GitHub repository is **private** you have to configure SSH or username/p
Configure seed job like: Configure seed job like:
``` ```
apiVersion: jenkins.io/v1alpha1 apiVersion: jenkins.io/v1alpha2
kind: Jenkins kind: Jenkins
metadata: metadata:
name: example name: example
@ -243,7 +243,7 @@ data:
Configure seed job like: Configure seed job like:
``` ```
apiVersion: jenkins.io/v1alpha1 apiVersion: jenkins.io/v1alpha2
kind: Jenkins kind: Jenkins
metadata: metadata:
name: example name: example
@ -350,7 +350,7 @@ runs the **jenkins-operator-user-configuration-casc** Jenkins Job which applies
Edit CR under `spec.master.plugins`: Edit CR under `spec.master.plugins`:
``` ```
apiVersion: jenkins.io/v1alpha1 apiVersion: jenkins.io/v1alpha2
kind: Jenkins kind: Jenkins
metadata: metadata:
name: example name: example

View File

@ -6,15 +6,15 @@ All container images can be found at [virtuslab/jenkins-operator](https://hub.do
## Requirements ## Requirements
To run **jenkins-operator**, you will need: To run **jenkins-operator**, you will need:
- running Kubernetes cluster - running Kubernetes cluster version 1.11+
- kubectl - kubectl version 1.11+
## Configure Custom Resource Definition ## Configure Custom Resource Definition
Install Jenkins Custom Resource Definition: Install Jenkins Custom Resource Definition:
```bash ```bash
kubectl apply -f https://raw.githubusercontent.com/jenkinsci/kubernetes-operator/master/deploy/crds/jenkins_v1alpha1_jenkins_crd.yaml kubectl apply -f https://raw.githubusercontent.com/jenkinsci/kubernetes-operator/master/deploy/crds/jenkins_v1alpha2_jenkins_crd.yaml
``` ```
## Deploy jenkins-operator ## Deploy jenkins-operator

View File

@ -7,7 +7,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha1" "github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2"
jenkinsclient "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/client" jenkinsclient "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/client"
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/base/resources" "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/base/resources"
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/constants" "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/constants"
@ -38,13 +38,13 @@ type ReconcileJenkinsBaseConfiguration struct {
k8sClient client.Client k8sClient client.Client
scheme *runtime.Scheme scheme *runtime.Scheme
logger logr.Logger logger logr.Logger
jenkins *v1alpha1.Jenkins jenkins *v1alpha2.Jenkins
local, minikube bool local, minikube bool
} }
// New create structure which takes care of base configuration // New create structure which takes care of base configuration
func New(client client.Client, scheme *runtime.Scheme, logger logr.Logger, func New(client client.Client, scheme *runtime.Scheme, logger logr.Logger,
jenkins *v1alpha1.Jenkins, local, minikube bool) *ReconcileJenkinsBaseConfiguration { jenkins *v1alpha2.Jenkins, local, minikube bool) *ReconcileJenkinsBaseConfiguration {
return &ReconcileJenkinsBaseConfiguration{ return &ReconcileJenkinsBaseConfiguration{
k8sClient: client, k8sClient: client,
scheme: scheme, scheme: scheme,
@ -364,7 +364,7 @@ func (r *ReconcileJenkinsBaseConfiguration) createRBAC(meta metav1.ObjectMeta) e
return nil return nil
} }
func (r *ReconcileJenkinsBaseConfiguration) createService(meta metav1.ObjectMeta, name string, config v1alpha1.Service) error { func (r *ReconcileJenkinsBaseConfiguration) createService(meta metav1.ObjectMeta, name string, config v1alpha2.Service) error {
service := corev1.Service{} service := corev1.Service{}
err := r.k8sClient.Get(context.TODO(), types.NamespacedName{Name: name, Namespace: meta.Namespace}, &service) err := r.k8sClient.Get(context.TODO(), types.NamespacedName{Name: name, Namespace: meta.Namespace}, &service)
if err != nil && errors.IsNotFound(err) { if err != nil && errors.IsNotFound(err) {
@ -410,7 +410,7 @@ func (r *ReconcileJenkinsBaseConfiguration) ensureJenkinsMasterPod(meta metav1.O
return reconcile.Result{}, stackerr.WithStack(err) return reconcile.Result{}, stackerr.WithStack(err)
} }
now := metav1.Now() now := metav1.Now()
r.jenkins.Status = v1alpha1.JenkinsStatus{ r.jenkins.Status = v1alpha2.JenkinsStatus{
ProvisionStartTime: &now, ProvisionStartTime: &now,
} }
err = r.updateResource(r.jenkins) err = r.updateResource(r.jenkins)

View File

@ -3,7 +3,7 @@ package base
import ( import (
"testing" "testing"
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha1" "github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2"
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/client" "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/client"
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/base/resources" "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/base/resources"
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/plugins" "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/plugins"
@ -92,7 +92,7 @@ func TestCompareContainerVolumeMounts(t *testing.T) {
func TestCompareVolumes(t *testing.T) { func TestCompareVolumes(t *testing.T) {
t.Run("defaults", func(t *testing.T) { t.Run("defaults", func(t *testing.T) {
jenkins := &v1alpha1.Jenkins{} jenkins := &v1alpha2.Jenkins{}
pod := corev1.Pod{ pod := corev1.Pod{
Spec: corev1.PodSpec{ Spec: corev1.PodSpec{
ServiceAccountName: "service-account-name", ServiceAccountName: "service-account-name",
@ -106,9 +106,9 @@ func TestCompareVolumes(t *testing.T) {
assert.True(t, got) assert.True(t, got)
}) })
t.Run("different", func(t *testing.T) { t.Run("different", func(t *testing.T) {
jenkins := &v1alpha1.Jenkins{ jenkins := &v1alpha2.Jenkins{
Spec: v1alpha1.JenkinsSpec{ Spec: v1alpha2.JenkinsSpec{
Master: v1alpha1.JenkinsMaster{ Master: v1alpha2.JenkinsMaster{
Volumes: []corev1.Volume{ Volumes: []corev1.Volume{
{ {
Name: "added", Name: "added",
@ -130,9 +130,9 @@ func TestCompareVolumes(t *testing.T) {
assert.False(t, got) assert.False(t, got)
}) })
t.Run("added one volume", func(t *testing.T) { t.Run("added one volume", func(t *testing.T) {
jenkins := &v1alpha1.Jenkins{ jenkins := &v1alpha2.Jenkins{
Spec: v1alpha1.JenkinsSpec{ Spec: v1alpha2.JenkinsSpec{
Master: v1alpha1.JenkinsMaster{ Master: v1alpha2.JenkinsMaster{
Volumes: []corev1.Volume{ Volumes: []corev1.Volume{
{ {
Name: "added", Name: "added",
@ -159,7 +159,7 @@ func TestReconcileJenkinsBaseConfiguration_verifyPlugins(t *testing.T) {
log.SetupLogger(true) log.SetupLogger(true)
t.Run("happy, empty base and user plugins", func(t *testing.T) { t.Run("happy, empty base and user plugins", func(t *testing.T) {
jenkins := &v1alpha1.Jenkins{} jenkins := &v1alpha2.Jenkins{}
r := ReconcileJenkinsBaseConfiguration{ r := ReconcileJenkinsBaseConfiguration{
logger: log.Log, logger: log.Log,
jenkins: jenkins, jenkins: jenkins,
@ -179,7 +179,7 @@ func TestReconcileJenkinsBaseConfiguration_verifyPlugins(t *testing.T) {
assert.True(t, got) assert.True(t, got)
}) })
t.Run("happy, not empty base and empty user plugins", func(t *testing.T) { t.Run("happy, not empty base and empty user plugins", func(t *testing.T) {
jenkins := &v1alpha1.Jenkins{} jenkins := &v1alpha2.Jenkins{}
r := ReconcileJenkinsBaseConfiguration{ r := ReconcileJenkinsBaseConfiguration{
logger: log.Log, logger: log.Log,
jenkins: jenkins, jenkins: jenkins,
@ -211,9 +211,9 @@ func TestReconcileJenkinsBaseConfiguration_verifyPlugins(t *testing.T) {
assert.True(t, got) assert.True(t, got)
}) })
t.Run("happy, empty base and not empty user plugins", func(t *testing.T) { t.Run("happy, empty base and not empty user plugins", func(t *testing.T) {
jenkins := &v1alpha1.Jenkins{ jenkins := &v1alpha2.Jenkins{
Spec: v1alpha1.JenkinsSpec{ Spec: v1alpha2.JenkinsSpec{
Master: v1alpha1.JenkinsMaster{ Master: v1alpha2.JenkinsMaster{
Plugins: map[string][]string{"plugin-name:0.0.1": {}}, Plugins: map[string][]string{"plugin-name:0.0.1": {}},
}, },
}, },
@ -247,7 +247,7 @@ func TestReconcileJenkinsBaseConfiguration_verifyPlugins(t *testing.T) {
assert.True(t, got) assert.True(t, got)
}) })
t.Run("happy, plugin version doesn't matter for base plugins", func(t *testing.T) { t.Run("happy, plugin version doesn't matter for base plugins", func(t *testing.T) {
jenkins := &v1alpha1.Jenkins{} jenkins := &v1alpha2.Jenkins{}
r := ReconcileJenkinsBaseConfiguration{ r := ReconcileJenkinsBaseConfiguration{
logger: log.Log, logger: log.Log,
jenkins: jenkins, jenkins: jenkins,
@ -279,9 +279,9 @@ func TestReconcileJenkinsBaseConfiguration_verifyPlugins(t *testing.T) {
assert.True(t, got) assert.True(t, got)
}) })
t.Run("plugin version matter for user plugins", func(t *testing.T) { t.Run("plugin version matter for user plugins", func(t *testing.T) {
jenkins := &v1alpha1.Jenkins{ jenkins := &v1alpha2.Jenkins{
Spec: v1alpha1.JenkinsSpec{ Spec: v1alpha2.JenkinsSpec{
Master: v1alpha1.JenkinsMaster{ Master: v1alpha2.JenkinsMaster{
Plugins: map[string][]string{"plugin-name:0.0.2": {}}, Plugins: map[string][]string{"plugin-name:0.0.2": {}},
}, },
}, },
@ -315,7 +315,7 @@ func TestReconcileJenkinsBaseConfiguration_verifyPlugins(t *testing.T) {
assert.False(t, got) assert.False(t, got)
}) })
t.Run("missing base plugin", func(t *testing.T) { t.Run("missing base plugin", func(t *testing.T) {
jenkins := &v1alpha1.Jenkins{} jenkins := &v1alpha2.Jenkins{}
r := ReconcileJenkinsBaseConfiguration{ r := ReconcileJenkinsBaseConfiguration{
logger: log.Log, logger: log.Log,
jenkins: jenkins, jenkins: jenkins,
@ -339,9 +339,9 @@ func TestReconcileJenkinsBaseConfiguration_verifyPlugins(t *testing.T) {
assert.False(t, got) assert.False(t, got)
}) })
t.Run("missing user plugin", func(t *testing.T) { t.Run("missing user plugin", func(t *testing.T) {
jenkins := &v1alpha1.Jenkins{ jenkins := &v1alpha2.Jenkins{
Spec: v1alpha1.JenkinsSpec{ Spec: v1alpha2.JenkinsSpec{
Master: v1alpha1.JenkinsMaster{ Master: v1alpha2.JenkinsMaster{
Plugins: map[string][]string{"plugin-name:0.0.2": {}}, Plugins: map[string][]string{"plugin-name:0.0.2": {}},
}, },
}, },

View File

@ -3,7 +3,7 @@ package resources
import ( import (
"fmt" "fmt"
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha1" "github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2"
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/constants" "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/constants"
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
@ -168,12 +168,12 @@ GlobalConfiguration.all().get(GlobalJobDslSecurityConfiguration.class).save()
` `
// GetBaseConfigurationConfigMapName returns name of Kubernetes config map used to base configuration // GetBaseConfigurationConfigMapName returns name of Kubernetes config map used to base configuration
func GetBaseConfigurationConfigMapName(jenkins *v1alpha1.Jenkins) string { func GetBaseConfigurationConfigMapName(jenkins *v1alpha2.Jenkins) string {
return fmt.Sprintf("%s-base-configuration-%s", constants.OperatorName, jenkins.ObjectMeta.Name) return fmt.Sprintf("%s-base-configuration-%s", constants.OperatorName, jenkins.ObjectMeta.Name)
} }
// NewBaseConfigurationConfigMap builds Kubernetes config map used to base configuration // NewBaseConfigurationConfigMap builds Kubernetes config map used to base configuration
func NewBaseConfigurationConfigMap(meta metav1.ObjectMeta, jenkins *v1alpha1.Jenkins) *corev1.ConfigMap { func NewBaseConfigurationConfigMap(meta metav1.ObjectMeta, jenkins *v1alpha2.Jenkins) *corev1.ConfigMap {
meta.Name = GetBaseConfigurationConfigMapName(jenkins) meta.Name = GetBaseConfigurationConfigMapName(jenkins)
return &corev1.ConfigMap{ return &corev1.ConfigMap{

View File

@ -5,7 +5,7 @@ import (
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/constants" "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/constants"
"text/template" "text/template"
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha1" "github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2"
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@ -57,12 +57,12 @@ func buildCreateJenkinsOperatorUserGroovyScript() (*string, error) {
} }
// GetInitConfigurationConfigMapName returns name of Kubernetes config map used to init configuration // GetInitConfigurationConfigMapName returns name of Kubernetes config map used to init configuration
func GetInitConfigurationConfigMapName(jenkins *v1alpha1.Jenkins) string { func GetInitConfigurationConfigMapName(jenkins *v1alpha2.Jenkins) string {
return fmt.Sprintf("%s-init-configuration-%s", constants.OperatorName, jenkins.ObjectMeta.Name) return fmt.Sprintf("%s-init-configuration-%s", constants.OperatorName, jenkins.ObjectMeta.Name)
} }
// NewInitConfigurationConfigMap builds Kubernetes config map used to init configuration // NewInitConfigurationConfigMap builds Kubernetes config map used to init configuration
func NewInitConfigurationConfigMap(meta metav1.ObjectMeta, jenkins *v1alpha1.Jenkins) (*corev1.ConfigMap, error) { func NewInitConfigurationConfigMap(meta metav1.ObjectMeta, jenkins *v1alpha2.Jenkins) (*corev1.ConfigMap, error) {
meta.Name = GetInitConfigurationConfigMapName(jenkins) meta.Name = GetInitConfigurationConfigMapName(jenkins)
createJenkinsOperatorUserGroovy, err := buildCreateJenkinsOperatorUserGroovyScript() createJenkinsOperatorUserGroovy, err := buildCreateJenkinsOperatorUserGroovyScript()

View File

@ -3,14 +3,14 @@ package resources
import ( import (
"fmt" "fmt"
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha1" "github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2"
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/constants" "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/constants"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
) )
// NewResourceObjectMeta builds ObjectMeta for all Kubernetes resources created by operator // NewResourceObjectMeta builds ObjectMeta for all Kubernetes resources created by operator
func NewResourceObjectMeta(jenkins *v1alpha1.Jenkins) metav1.ObjectMeta { func NewResourceObjectMeta(jenkins *v1alpha2.Jenkins) metav1.ObjectMeta {
return metav1.ObjectMeta{ return metav1.ObjectMeta{
Name: GetResourceName(jenkins), Name: GetResourceName(jenkins),
Namespace: jenkins.ObjectMeta.Namespace, Namespace: jenkins.ObjectMeta.Namespace,
@ -19,7 +19,7 @@ func NewResourceObjectMeta(jenkins *v1alpha1.Jenkins) metav1.ObjectMeta {
} }
// BuildResourceLabels returns labels for all Kubernetes resources created by operator // BuildResourceLabels returns labels for all Kubernetes resources created by operator
func BuildResourceLabels(jenkins *v1alpha1.Jenkins) map[string]string { func BuildResourceLabels(jenkins *v1alpha2.Jenkins) map[string]string {
return map[string]string{ return map[string]string{
constants.LabelAppKey: constants.LabelAppValue, constants.LabelAppKey: constants.LabelAppValue,
constants.LabelJenkinsCRKey: jenkins.Name, constants.LabelJenkinsCRKey: jenkins.Name,
@ -29,7 +29,7 @@ func BuildResourceLabels(jenkins *v1alpha1.Jenkins) map[string]string {
// BuildLabelsForWatchedResources returns labels for Kubernetes resources which operator want to watch // BuildLabelsForWatchedResources returns labels for Kubernetes resources which operator want to watch
// resources with that labels should not be deleted after Jenkins CR deletion, to prevent this situation don't set // resources with that labels should not be deleted after Jenkins CR deletion, to prevent this situation don't set
// any owner // any owner
func BuildLabelsForWatchedResources(jenkins v1alpha1.Jenkins) map[string]string { func BuildLabelsForWatchedResources(jenkins v1alpha2.Jenkins) map[string]string {
return map[string]string{ return map[string]string{
constants.LabelAppKey: constants.LabelAppValue, constants.LabelAppKey: constants.LabelAppValue,
constants.LabelJenkinsCRKey: jenkins.Name, constants.LabelJenkinsCRKey: jenkins.Name,
@ -38,7 +38,7 @@ func BuildLabelsForWatchedResources(jenkins v1alpha1.Jenkins) map[string]string
} }
// GetResourceName returns name of Kubernetes resource base on Jenkins CR // GetResourceName returns name of Kubernetes resource base on Jenkins CR
func GetResourceName(jenkins *v1alpha1.Jenkins) string { func GetResourceName(jenkins *v1alpha2.Jenkins) string {
return fmt.Sprintf("%s-%s", constants.LabelAppValue, jenkins.ObjectMeta.Name) return fmt.Sprintf("%s-%s", constants.LabelAppValue, jenkins.ObjectMeta.Name)
} }

View File

@ -3,7 +3,7 @@ package resources
import ( import (
"fmt" "fmt"
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha1" "github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2"
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/constants" "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/constants"
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
@ -32,13 +32,13 @@ func buildSecretTypeMeta() metav1.TypeMeta {
// GetOperatorCredentialsSecretName returns name of Kubernetes secret used to store jenkins operator credentials // GetOperatorCredentialsSecretName returns name of Kubernetes secret used to store jenkins operator credentials
// to allow calls to Jenkins API // to allow calls to Jenkins API
func GetOperatorCredentialsSecretName(jenkins *v1alpha1.Jenkins) string { func GetOperatorCredentialsSecretName(jenkins *v1alpha2.Jenkins) string {
return fmt.Sprintf("%s-credentials-%s", constants.OperatorName, jenkins.Name) return fmt.Sprintf("%s-credentials-%s", constants.OperatorName, jenkins.Name)
} }
// NewOperatorCredentialsSecret builds the Kubernetes secret used to store jenkins operator credentials // NewOperatorCredentialsSecret builds the Kubernetes secret used to store jenkins operator credentials
// to allow calls to Jenkins API // to allow calls to Jenkins API
func NewOperatorCredentialsSecret(meta metav1.ObjectMeta, jenkins *v1alpha1.Jenkins) *corev1.Secret { func NewOperatorCredentialsSecret(meta metav1.ObjectMeta, jenkins *v1alpha2.Jenkins) *corev1.Secret {
meta.Name = GetOperatorCredentialsSecretName(jenkins) meta.Name = GetOperatorCredentialsSecretName(jenkins)
return &corev1.Secret{ return &corev1.Secret{
TypeMeta: buildSecretTypeMeta(), TypeMeta: buildSecretTypeMeta(),

View File

@ -3,7 +3,7 @@ package resources
import ( import (
"fmt" "fmt"
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha1" "github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2"
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/constants" "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/constants"
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
@ -76,7 +76,7 @@ func GetJenkinsMasterPodBaseEnvs() []corev1.EnvVar {
} }
// GetJenkinsMasterPodBaseVolumes returns Jenkins master pod volumes required by operator // GetJenkinsMasterPodBaseVolumes returns Jenkins master pod volumes required by operator
func GetJenkinsMasterPodBaseVolumes(jenkins *v1alpha1.Jenkins) []corev1.Volume { func GetJenkinsMasterPodBaseVolumes(jenkins *v1alpha2.Jenkins) []corev1.Volume {
configMapVolumeSourceDefaultMode := corev1.ConfigMapVolumeSourceDefaultMode configMapVolumeSourceDefaultMode := corev1.ConfigMapVolumeSourceDefaultMode
secretVolumeSourceDefaultMode := corev1.SecretVolumeSourceDefaultMode secretVolumeSourceDefaultMode := corev1.SecretVolumeSourceDefaultMode
return []corev1.Volume{ return []corev1.Volume{
@ -193,7 +193,7 @@ func GetJenkinsMasterContainerBaseVolumeMounts() []corev1.VolumeMount {
} }
// NewJenkinsMasterContainer returns Jenkins master Kubernetes container // NewJenkinsMasterContainer returns Jenkins master Kubernetes container
func NewJenkinsMasterContainer(jenkins *v1alpha1.Jenkins) corev1.Container { func NewJenkinsMasterContainer(jenkins *v1alpha2.Jenkins) corev1.Container {
envs := GetJenkinsMasterPodBaseEnvs() envs := GetJenkinsMasterPodBaseEnvs()
envs = append(envs, jenkins.Spec.Master.Env...) envs = append(envs, jenkins.Spec.Master.Env...)
@ -226,7 +226,7 @@ func NewJenkinsMasterContainer(jenkins *v1alpha1.Jenkins) corev1.Container {
} }
// ConvertJenkinsContainerToKubernetesContainer converts Jenkins container to Kubernetes container // ConvertJenkinsContainerToKubernetesContainer converts Jenkins container to Kubernetes container
func ConvertJenkinsContainerToKubernetesContainer(container v1alpha1.Container) corev1.Container { func ConvertJenkinsContainerToKubernetesContainer(container v1alpha2.Container) corev1.Container {
return corev1.Container{ return corev1.Container{
Name: container.Name, Name: container.Name,
Image: container.Image, Image: container.Image,
@ -246,7 +246,7 @@ func ConvertJenkinsContainerToKubernetesContainer(container v1alpha1.Container)
} }
} }
func newContainers(jenkins *v1alpha1.Jenkins) (containers []corev1.Container) { func newContainers(jenkins *v1alpha2.Jenkins) (containers []corev1.Container) {
containers = append(containers, NewJenkinsMasterContainer(jenkins)) containers = append(containers, NewJenkinsMasterContainer(jenkins))
for _, container := range jenkins.Spec.Master.Containers { for _, container := range jenkins.Spec.Master.Containers {
@ -257,7 +257,7 @@ func newContainers(jenkins *v1alpha1.Jenkins) (containers []corev1.Container) {
} }
// NewJenkinsMasterPod builds Jenkins Master Kubernetes Pod resource // NewJenkinsMasterPod builds Jenkins Master Kubernetes Pod resource
func NewJenkinsMasterPod(objectMeta metav1.ObjectMeta, jenkins *v1alpha1.Jenkins) *corev1.Pod { func NewJenkinsMasterPod(objectMeta metav1.ObjectMeta, jenkins *v1alpha2.Jenkins) *corev1.Pod {
runAsUser := jenkinsUserUID runAsUser := jenkinsUserUID
objectMeta.Annotations = jenkins.Spec.Master.Annotations objectMeta.Annotations = jenkins.Spec.Master.Annotations

View File

@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"text/template" "text/template"
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha1" "github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2"
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/constants" "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/constants"
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
@ -278,7 +278,7 @@ func buildConfigMapTypeMeta() metav1.TypeMeta {
} }
} }
func buildInitBashScript(jenkins *v1alpha1.Jenkins) (*string, error) { func buildInitBashScript(jenkins *v1alpha2.Jenkins) (*string, error) {
data := struct { data := struct {
JenkinsHomePath string JenkinsHomePath string
InitConfigurationPath string InitConfigurationPath string
@ -303,12 +303,12 @@ func buildInitBashScript(jenkins *v1alpha1.Jenkins) (*string, error) {
return &output, nil return &output, nil
} }
func getScriptsConfigMapName(jenkins *v1alpha1.Jenkins) string { func getScriptsConfigMapName(jenkins *v1alpha2.Jenkins) string {
return fmt.Sprintf("%s-scripts-%s", constants.OperatorName, jenkins.ObjectMeta.Name) return fmt.Sprintf("%s-scripts-%s", constants.OperatorName, jenkins.ObjectMeta.Name)
} }
// NewScriptsConfigMap builds Kubernetes config map used to store scripts // NewScriptsConfigMap builds Kubernetes config map used to store scripts
func NewScriptsConfigMap(meta metav1.ObjectMeta, jenkins *v1alpha1.Jenkins) (*corev1.ConfigMap, error) { func NewScriptsConfigMap(meta metav1.ObjectMeta, jenkins *v1alpha2.Jenkins) (*corev1.ConfigMap, error) {
meta.Name = getScriptsConfigMapName(jenkins) meta.Name = getScriptsConfigMapName(jenkins)
initBashScript, err := buildInitBashScript(jenkins) initBashScript, err := buildInitBashScript(jenkins)

View File

@ -3,7 +3,7 @@ package resources
import ( import (
"fmt" "fmt"
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha1" "github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2"
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/constants" "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/constants"
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
@ -18,7 +18,7 @@ func buildServiceTypeMeta() metav1.TypeMeta {
} }
// UpdateService returns new service with override fields from config // UpdateService returns new service with override fields from config
func UpdateService(actual corev1.Service, config v1alpha1.Service) corev1.Service { func UpdateService(actual corev1.Service, config v1alpha2.Service) corev1.Service {
actual.ObjectMeta.Annotations = config.Annotations actual.ObjectMeta.Annotations = config.Annotations
for key, value := range config.Labels { for key, value := range config.Labels {
actual.ObjectMeta.Labels[key] = value actual.ObjectMeta.Labels[key] = value
@ -38,11 +38,11 @@ func UpdateService(actual corev1.Service, config v1alpha1.Service) corev1.Servic
} }
// GetJenkinsHTTPServiceName returns Kubernetes service name used for expose Jenkins HTTP endpoint // GetJenkinsHTTPServiceName returns Kubernetes service name used for expose Jenkins HTTP endpoint
func GetJenkinsHTTPServiceName(jenkins *v1alpha1.Jenkins) string { func GetJenkinsHTTPServiceName(jenkins *v1alpha2.Jenkins) string {
return fmt.Sprintf("%s-http-%s", constants.OperatorName, jenkins.ObjectMeta.Name) return fmt.Sprintf("%s-http-%s", constants.OperatorName, jenkins.ObjectMeta.Name)
} }
// GetJenkinsSlavesServiceName returns Kubernetes service name used for expose Jenkins slave endpoint // GetJenkinsSlavesServiceName returns Kubernetes service name used for expose Jenkins slave endpoint
func GetJenkinsSlavesServiceName(jenkins *v1alpha1.Jenkins) string { func GetJenkinsSlavesServiceName(jenkins *v1alpha2.Jenkins) string {
return fmt.Sprintf("%s-slave-%s", constants.OperatorName, jenkins.ObjectMeta.Name) return fmt.Sprintf("%s-slave-%s", constants.OperatorName, jenkins.ObjectMeta.Name)
} }

View File

@ -3,7 +3,7 @@ package resources
import ( import (
"fmt" "fmt"
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha1" "github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2"
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/constants" "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/constants"
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
@ -33,7 +33,7 @@ jenkins.save()
` `
// GetUserConfigurationConfigMapNameFromJenkins returns name of Kubernetes config map used to user configuration // GetUserConfigurationConfigMapNameFromJenkins returns name of Kubernetes config map used to user configuration
func GetUserConfigurationConfigMapNameFromJenkins(jenkins *v1alpha1.Jenkins) string { func GetUserConfigurationConfigMapNameFromJenkins(jenkins *v1alpha2.Jenkins) string {
return fmt.Sprintf("%s-user-configuration-%s", constants.OperatorName, jenkins.ObjectMeta.Name) return fmt.Sprintf("%s-user-configuration-%s", constants.OperatorName, jenkins.ObjectMeta.Name)
} }
@ -43,7 +43,7 @@ func GetUserConfigurationConfigMapName(jenkinsCRName string) string {
} }
// NewUserConfigurationConfigMap builds Kubernetes config map used to user configuration // NewUserConfigurationConfigMap builds Kubernetes config map used to user configuration
func NewUserConfigurationConfigMap(jenkins *v1alpha1.Jenkins) *corev1.ConfigMap { func NewUserConfigurationConfigMap(jenkins *v1alpha2.Jenkins) *corev1.ConfigMap {
return &corev1.ConfigMap{ return &corev1.ConfigMap{
TypeMeta: buildConfigMapTypeMeta(), TypeMeta: buildConfigMapTypeMeta(),
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{

View File

@ -3,7 +3,7 @@ package resources
import ( import (
"fmt" "fmt"
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha1" "github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2"
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/constants" "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/constants"
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
@ -11,7 +11,7 @@ import (
) )
// GetUserConfigurationSecretNameFromJenkins returns name of Kubernetes secret used to store jenkins operator credentials // GetUserConfigurationSecretNameFromJenkins returns name of Kubernetes secret used to store jenkins operator credentials
func GetUserConfigurationSecretNameFromJenkins(jenkins *v1alpha1.Jenkins) string { func GetUserConfigurationSecretNameFromJenkins(jenkins *v1alpha2.Jenkins) string {
return fmt.Sprintf("%s-user-configuration-%s", constants.OperatorName, jenkins.Name) return fmt.Sprintf("%s-user-configuration-%s", constants.OperatorName, jenkins.Name)
} }
@ -21,7 +21,7 @@ func GetUserConfigurationSecretName(jenkinsCRName string) string {
} }
// NewUserConfigurationSecret builds the Kubernetes secret resource which is used to store user sensitive data for Jenkins configuration // NewUserConfigurationSecret builds the Kubernetes secret resource which is used to store user sensitive data for Jenkins configuration
func NewUserConfigurationSecret(jenkins *v1alpha1.Jenkins) *corev1.Secret { func NewUserConfigurationSecret(jenkins *v1alpha2.Jenkins) *corev1.Secret {
return &corev1.Secret{ return &corev1.Secret{
TypeMeta: buildServiceTypeMeta(), TypeMeta: buildServiceTypeMeta(),
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{

View File

@ -5,7 +5,7 @@ import (
"fmt" "fmt"
"regexp" "regexp"
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha1" "github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2"
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/base/resources" "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/base/resources"
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/plugins" "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/plugins"
"github.com/jenkinsci/kubernetes-operator/pkg/log" "github.com/jenkinsci/kubernetes-operator/pkg/log"
@ -22,7 +22,7 @@ var (
) )
// Validate validates Jenkins CR Spec.master section // Validate validates Jenkins CR Spec.master section
func (r *ReconcileJenkinsBaseConfiguration) Validate(jenkins *v1alpha1.Jenkins) (bool, error) { func (r *ReconcileJenkinsBaseConfiguration) Validate(jenkins *v1alpha2.Jenkins) (bool, error) {
if !r.validateReservedVolumes() { if !r.validateReservedVolumes() {
return false, nil return false, nil
} }
@ -146,7 +146,7 @@ func (r *ReconcileJenkinsBaseConfiguration) validateReservedVolumes() bool {
return valid return valid
} }
func (r *ReconcileJenkinsBaseConfiguration) validateContainer(container v1alpha1.Container) bool { func (r *ReconcileJenkinsBaseConfiguration) validateContainer(container v1alpha2.Container) bool {
logger := r.logger.WithValues("container", container.Name) logger := r.logger.WithValues("container", container.Name)
if container.Image == "" { if container.Image == "" {
logger.V(log.VWarn).Info("Image not set") logger.V(log.VWarn).Info("Image not set")
@ -170,7 +170,7 @@ func (r *ReconcileJenkinsBaseConfiguration) validateContainer(container v1alpha1
return true return true
} }
func (r *ReconcileJenkinsBaseConfiguration) validateContainerVolumeMounts(container v1alpha1.Container) bool { func (r *ReconcileJenkinsBaseConfiguration) validateContainerVolumeMounts(container v1alpha2.Container) bool {
logger := r.logger.WithValues("container", container.Name) logger := r.logger.WithValues("container", container.Name)
allVolumes := append(resources.GetJenkinsMasterPodBaseVolumes(r.jenkins), r.jenkins.Spec.Master.Volumes...) allVolumes := append(resources.GetJenkinsMasterPodBaseVolumes(r.jenkins), r.jenkins.Spec.Master.Volumes...)
valid := true valid := true

View File

@ -4,7 +4,7 @@ import (
"context" "context"
"testing" "testing"
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha1" "github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2"
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/base/resources" "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/base/resources"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -76,10 +76,10 @@ func TestValidatePlugins(t *testing.T) {
func TestValidateJenkinsMasterPodEnvs(t *testing.T) { func TestValidateJenkinsMasterPodEnvs(t *testing.T) {
t.Run("happy", func(t *testing.T) { t.Run("happy", func(t *testing.T) {
jenkins := v1alpha1.Jenkins{ jenkins := v1alpha2.Jenkins{
Spec: v1alpha1.JenkinsSpec{ Spec: v1alpha2.JenkinsSpec{
Master: v1alpha1.JenkinsMaster{ Master: v1alpha2.JenkinsMaster{
Container: v1alpha1.Container{ Container: v1alpha2.Container{
Env: []v1.EnvVar{ Env: []v1.EnvVar{
{ {
Name: "SOME_VALUE", Name: "SOME_VALUE",
@ -96,10 +96,10 @@ func TestValidateJenkinsMasterPodEnvs(t *testing.T) {
assert.Equal(t, true, got) assert.Equal(t, true, got)
}) })
t.Run("override JENKINS_HOME env", func(t *testing.T) { t.Run("override JENKINS_HOME env", func(t *testing.T) {
jenkins := v1alpha1.Jenkins{ jenkins := v1alpha2.Jenkins{
Spec: v1alpha1.JenkinsSpec{ Spec: v1alpha2.JenkinsSpec{
Master: v1alpha1.JenkinsMaster{ Master: v1alpha2.JenkinsMaster{
Container: v1alpha1.Container{ Container: v1alpha2.Container{
Env: []v1.EnvVar{ Env: []v1.EnvVar{
{ {
Name: "JENKINS_HOME", Name: "JENKINS_HOME",
@ -119,9 +119,9 @@ func TestValidateJenkinsMasterPodEnvs(t *testing.T) {
func TestValidateReservedVolumes(t *testing.T) { func TestValidateReservedVolumes(t *testing.T) {
t.Run("happy", func(t *testing.T) { t.Run("happy", func(t *testing.T) {
jenkins := v1alpha1.Jenkins{ jenkins := v1alpha2.Jenkins{
Spec: v1alpha1.JenkinsSpec{ Spec: v1alpha2.JenkinsSpec{
Master: v1alpha1.JenkinsMaster{ Master: v1alpha2.JenkinsMaster{
Volumes: []v1.Volume{ Volumes: []v1.Volume{
{ {
Name: "not-used-name", Name: "not-used-name",
@ -136,9 +136,9 @@ func TestValidateReservedVolumes(t *testing.T) {
assert.Equal(t, true, got) assert.Equal(t, true, got)
}) })
t.Run("used reserved name", func(t *testing.T) { t.Run("used reserved name", func(t *testing.T) {
jenkins := v1alpha1.Jenkins{ jenkins := v1alpha2.Jenkins{
Spec: v1alpha1.JenkinsSpec{ Spec: v1alpha2.JenkinsSpec{
Master: v1alpha1.JenkinsMaster{ Master: v1alpha2.JenkinsMaster{
Volumes: []v1.Volume{ Volumes: []v1.Volume{
{ {
Name: resources.JenkinsHomeVolumeName, Name: resources.JenkinsHomeVolumeName,
@ -156,9 +156,9 @@ func TestValidateReservedVolumes(t *testing.T) {
func TestValidateContainerVolumeMounts(t *testing.T) { func TestValidateContainerVolumeMounts(t *testing.T) {
t.Run("default Jenkins master container", func(t *testing.T) { t.Run("default Jenkins master container", func(t *testing.T) {
jenkins := v1alpha1.Jenkins{ jenkins := v1alpha2.Jenkins{
Spec: v1alpha1.JenkinsSpec{ Spec: v1alpha2.JenkinsSpec{
Master: v1alpha1.JenkinsMaster{}, Master: v1alpha2.JenkinsMaster{},
}, },
} }
baseReconcileLoop := New(nil, nil, logf.ZapLogger(false), baseReconcileLoop := New(nil, nil, logf.ZapLogger(false),
@ -167,15 +167,15 @@ func TestValidateContainerVolumeMounts(t *testing.T) {
assert.Equal(t, true, got) assert.Equal(t, true, got)
}) })
t.Run("one extra volume", func(t *testing.T) { t.Run("one extra volume", func(t *testing.T) {
jenkins := v1alpha1.Jenkins{ jenkins := v1alpha2.Jenkins{
Spec: v1alpha1.JenkinsSpec{ Spec: v1alpha2.JenkinsSpec{
Master: v1alpha1.JenkinsMaster{ Master: v1alpha2.JenkinsMaster{
Volumes: []v1.Volume{ Volumes: []v1.Volume{
{ {
Name: "example", Name: "example",
}, },
}, },
Container: v1alpha1.Container{ Container: v1alpha2.Container{
VolumeMounts: []v1.VolumeMount{ VolumeMounts: []v1.VolumeMount{
{ {
Name: "example", Name: "example",
@ -192,15 +192,15 @@ func TestValidateContainerVolumeMounts(t *testing.T) {
assert.Equal(t, true, got) assert.Equal(t, true, got)
}) })
t.Run("empty mountPath", func(t *testing.T) { t.Run("empty mountPath", func(t *testing.T) {
jenkins := v1alpha1.Jenkins{ jenkins := v1alpha2.Jenkins{
Spec: v1alpha1.JenkinsSpec{ Spec: v1alpha2.JenkinsSpec{
Master: v1alpha1.JenkinsMaster{ Master: v1alpha2.JenkinsMaster{
Volumes: []v1.Volume{ Volumes: []v1.Volume{
{ {
Name: "example", Name: "example",
}, },
}, },
Container: v1alpha1.Container{ Container: v1alpha2.Container{
VolumeMounts: []v1.VolumeMount{ VolumeMounts: []v1.VolumeMount{
{ {
Name: "example", Name: "example",
@ -217,10 +217,10 @@ func TestValidateContainerVolumeMounts(t *testing.T) {
assert.Equal(t, false, got) assert.Equal(t, false, got)
}) })
t.Run("missing volume", func(t *testing.T) { t.Run("missing volume", func(t *testing.T) {
jenkins := v1alpha1.Jenkins{ jenkins := v1alpha2.Jenkins{
Spec: v1alpha1.JenkinsSpec{ Spec: v1alpha2.JenkinsSpec{
Master: v1alpha1.JenkinsMaster{ Master: v1alpha2.JenkinsMaster{
Container: v1alpha1.Container{ Container: v1alpha2.Container{
VolumeMounts: []v1.VolumeMount{ VolumeMounts: []v1.VolumeMount{
{ {
Name: "missing-volume", Name: "missing-volume",
@ -262,7 +262,7 @@ func TestValidateConfigMapVolume(t *testing.T) {
t.Run("happy, required", func(t *testing.T) { t.Run("happy, required", func(t *testing.T) {
optional := false optional := false
configMap := corev1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Namespace: namespace, Name: "configmap-name"}} configMap := corev1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Namespace: namespace, Name: "configmap-name"}}
jenkins := &v1alpha1.Jenkins{ObjectMeta: metav1.ObjectMeta{Namespace: namespace}} jenkins := &v1alpha2.Jenkins{ObjectMeta: metav1.ObjectMeta{Namespace: namespace}}
volume := corev1.Volume{ volume := corev1.Volume{
Name: "volume-name", Name: "volume-name",
VolumeSource: corev1.VolumeSource{ VolumeSource: corev1.VolumeSource{
@ -288,7 +288,7 @@ func TestValidateConfigMapVolume(t *testing.T) {
t.Run("missing configmap", func(t *testing.T) { t.Run("missing configmap", func(t *testing.T) {
optional := false optional := false
configMap := corev1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Namespace: namespace, Name: "configmap-name"}} configMap := corev1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Namespace: namespace, Name: "configmap-name"}}
jenkins := &v1alpha1.Jenkins{ObjectMeta: metav1.ObjectMeta{Namespace: namespace}} jenkins := &v1alpha2.Jenkins{ObjectMeta: metav1.ObjectMeta{Namespace: namespace}}
volume := corev1.Volume{ volume := corev1.Volume{
Name: "volume-name", Name: "volume-name",
VolumeSource: corev1.VolumeSource{ VolumeSource: corev1.VolumeSource{
@ -335,7 +335,7 @@ func TestValidateSecretVolume(t *testing.T) {
t.Run("happy, required", func(t *testing.T) { t.Run("happy, required", func(t *testing.T) {
optional := false optional := false
secret := corev1.Secret{ObjectMeta: metav1.ObjectMeta{Namespace: namespace, Name: "secret-name"}} secret := corev1.Secret{ObjectMeta: metav1.ObjectMeta{Namespace: namespace, Name: "secret-name"}}
jenkins := &v1alpha1.Jenkins{ObjectMeta: metav1.ObjectMeta{Namespace: namespace}} jenkins := &v1alpha2.Jenkins{ObjectMeta: metav1.ObjectMeta{Namespace: namespace}}
volume := corev1.Volume{ volume := corev1.Volume{
Name: "volume-name", Name: "volume-name",
VolumeSource: corev1.VolumeSource{ VolumeSource: corev1.VolumeSource{
@ -359,7 +359,7 @@ func TestValidateSecretVolume(t *testing.T) {
t.Run("missing secret", func(t *testing.T) { t.Run("missing secret", func(t *testing.T) {
optional := false optional := false
secret := corev1.Secret{ObjectMeta: metav1.ObjectMeta{Namespace: namespace, Name: "secret-name"}} secret := corev1.Secret{ObjectMeta: metav1.ObjectMeta{Namespace: namespace, Name: "secret-name"}}
jenkins := &v1alpha1.Jenkins{ObjectMeta: metav1.ObjectMeta{Namespace: namespace}} jenkins := &v1alpha2.Jenkins{ObjectMeta: metav1.ObjectMeta{Namespace: namespace}}
volume := corev1.Volume{ volume := corev1.Volume{
Name: "volume-name", Name: "volume-name",
VolumeSource: corev1.VolumeSource{ VolumeSource: corev1.VolumeSource{

View File

@ -8,7 +8,7 @@ import (
"sort" "sort"
"strings" "strings"
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha1" "github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2"
jenkinsclient "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/client" jenkinsclient "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/client"
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/base/resources" "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/base/resources"
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/jobs" "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/jobs"
@ -56,7 +56,7 @@ func (g *ConfigurationAsCode) ConfigureJob() error {
} }
// Ensure configures Jenkins with help Configuration as a code plugin // Ensure configures Jenkins with help Configuration as a code plugin
func (g *ConfigurationAsCode) Ensure(jenkins *v1alpha1.Jenkins) (bool, error) { func (g *ConfigurationAsCode) Ensure(jenkins *v1alpha2.Jenkins) (bool, error) {
jobsClient := jobs.New(g.jenkinsClient, g.k8sClient, g.logger) jobsClient := jobs.New(g.jenkinsClient, g.k8sClient, g.logger)
configuration := &corev1.ConfigMap{} configuration := &corev1.ConfigMap{}

View File

@ -4,7 +4,7 @@ import (
"context" "context"
"time" "time"
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha1" "github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2"
jenkinsclient "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/client" jenkinsclient "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/client"
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/base/resources" "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/base/resources"
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/user/casc" "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/user/casc"
@ -26,12 +26,12 @@ type ReconcileUserConfiguration struct {
k8sClient k8s.Client k8sClient k8s.Client
jenkinsClient jenkinsclient.Jenkins jenkinsClient jenkinsclient.Jenkins
logger logr.Logger logger logr.Logger
jenkins *v1alpha1.Jenkins jenkins *v1alpha2.Jenkins
} }
// New create structure which takes care of user configuration // New create structure which takes care of user configuration
func New(k8sClient k8s.Client, jenkinsClient jenkinsclient.Jenkins, logger logr.Logger, func New(k8sClient k8s.Client, jenkinsClient jenkinsclient.Jenkins, logger logr.Logger,
jenkins *v1alpha1.Jenkins) *ReconcileUserConfiguration { jenkins *v1alpha2.Jenkins) *ReconcileUserConfiguration {
return &ReconcileUserConfiguration{ return &ReconcileUserConfiguration{
k8sClient: k8sClient, k8sClient: k8sClient,
jenkinsClient: jenkinsClient, jenkinsClient: jenkinsClient,

View File

@ -6,7 +6,7 @@ import (
"encoding/base64" "encoding/base64"
"fmt" "fmt"
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha1" "github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2"
jenkinsclient "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/client" jenkinsclient "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/client"
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/base/resources" "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/base/resources"
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/constants" "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/constants"
@ -60,7 +60,7 @@ func New(jenkinsClient jenkinsclient.Jenkins, k8sClient k8s.Client, logger logr.
} }
// EnsureSeedJobs configures seed job and runs it for every entry from Jenkins.Spec.SeedJobs // EnsureSeedJobs configures seed job and runs it for every entry from Jenkins.Spec.SeedJobs
func (s *SeedJobs) EnsureSeedJobs(jenkins *v1alpha1.Jenkins) (done bool, err error) { func (s *SeedJobs) EnsureSeedJobs(jenkins *v1alpha2.Jenkins) (done bool, err error) {
if err = s.createJob(); err != nil { if err = s.createJob(); err != nil {
s.logger.V(log.VWarn).Info("Couldn't create jenkins seed job") s.logger.V(log.VWarn).Info("Couldn't create jenkins seed job")
return false, err return false, err
@ -93,9 +93,9 @@ func (s *SeedJobs) createJob() error {
// ensureLabelsForSecrets adds labels to Kubernetes secrets where are Jenkins credentials used for seed jobs, // ensureLabelsForSecrets adds labels to Kubernetes secrets where are Jenkins credentials used for seed jobs,
// thanks to them kubernetes-credentials-provider-plugin will create Jenkins credentials in Jenkins and // thanks to them kubernetes-credentials-provider-plugin will create Jenkins credentials in Jenkins and
// Operator will able to watch any changes made to them // Operator will able to watch any changes made to them
func (s *SeedJobs) ensureLabelsForSecrets(jenkins v1alpha1.Jenkins) error { func (s *SeedJobs) ensureLabelsForSecrets(jenkins v1alpha2.Jenkins) error {
for _, seedJob := range jenkins.Spec.SeedJobs { for _, seedJob := range jenkins.Spec.SeedJobs {
if seedJob.JenkinsCredentialType == v1alpha1.BasicSSHCredentialType || seedJob.JenkinsCredentialType == v1alpha1.UsernamePasswordCredentialType { if seedJob.JenkinsCredentialType == v1alpha2.BasicSSHCredentialType || seedJob.JenkinsCredentialType == v1alpha2.UsernamePasswordCredentialType {
requiredLabels := resources.BuildLabelsForWatchedResources(jenkins) requiredLabels := resources.BuildLabelsForWatchedResources(jenkins)
requiredLabels[JenkinsCredentialTypeLabelName] = string(seedJob.JenkinsCredentialType) requiredLabels[JenkinsCredentialTypeLabelName] = string(seedJob.JenkinsCredentialType)
@ -120,7 +120,7 @@ func (s *SeedJobs) ensureLabelsForSecrets(jenkins v1alpha1.Jenkins) error {
} }
// buildJobs is responsible for running jenkins builds which configures jenkins seed jobs and deploy keys // buildJobs is responsible for running jenkins builds which configures jenkins seed jobs and deploy keys
func (s *SeedJobs) buildJobs(jenkins *v1alpha1.Jenkins) (done bool, err error) { func (s *SeedJobs) buildJobs(jenkins *v1alpha2.Jenkins) (done bool, err error) {
allDone := true allDone := true
for _, seedJob := range jenkins.Spec.SeedJobs { for _, seedJob := range jenkins.Spec.SeedJobs {
credentialValue, err := s.credentialValue(jenkins.Namespace, seedJob) credentialValue, err := s.credentialValue(jenkins.Namespace, seedJob)
@ -158,8 +158,8 @@ func (s *SeedJobs) buildJobs(jenkins *v1alpha1.Jenkins) (done bool, err error) {
return allDone, nil return allDone, nil
} }
func (s *SeedJobs) credentialValue(namespace string, seedJob v1alpha1.SeedJob) (string, error) { func (s *SeedJobs) credentialValue(namespace string, seedJob v1alpha2.SeedJob) (string, error) {
if seedJob.JenkinsCredentialType == v1alpha1.BasicSSHCredentialType || seedJob.JenkinsCredentialType == v1alpha1.UsernamePasswordCredentialType { if seedJob.JenkinsCredentialType == v1alpha2.BasicSSHCredentialType || seedJob.JenkinsCredentialType == v1alpha2.UsernamePasswordCredentialType {
secret := &corev1.Secret{} secret := &corev1.Secret{}
namespaceName := types.NamespacedName{Namespace: namespace, Name: seedJob.CredentialID} namespaceName := types.NamespacedName{Namespace: namespace, Name: seedJob.CredentialID}
err := s.k8sClient.Get(context.TODO(), namespaceName, secret) err := s.k8sClient.Get(context.TODO(), namespaceName, secret)
@ -167,7 +167,7 @@ func (s *SeedJobs) credentialValue(namespace string, seedJob v1alpha1.SeedJob) (
return "", err return "", err
} }
if seedJob.JenkinsCredentialType == v1alpha1.BasicSSHCredentialType { if seedJob.JenkinsCredentialType == v1alpha2.BasicSSHCredentialType {
return string(secret.Data[PrivateKeySecretKey]), nil return string(secret.Data[PrivateKeySecretKey]), nil
} }
return string(secret.Data[UsernameSecretKey]) + string(secret.Data[PasswordSecretKey]), nil return string(secret.Data[UsernameSecretKey]) + string(secret.Data[PasswordSecretKey]), nil

View File

@ -5,7 +5,7 @@ import (
"fmt" "fmt"
"testing" "testing"
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha1" "github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2"
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/client" "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/client"
"github.com/bndr/gojenkins" "github.com/bndr/gojenkins"
@ -29,7 +29,7 @@ func TestEnsureSeedJobs(t *testing.T) {
jenkinsClient := client.NewMockJenkins(ctrl) jenkinsClient := client.NewMockJenkins(ctrl)
fakeClient := fake.NewFakeClient() fakeClient := fake.NewFakeClient()
err := v1alpha1.SchemeBuilder.AddToScheme(scheme.Scheme) err := v1alpha2.SchemeBuilder.AddToScheme(scheme.Scheme)
assert.NoError(t, err) assert.NoError(t, err)
jenkins := jenkinsCustomResource() jenkins := jenkinsCustomResource()
@ -76,7 +76,7 @@ func TestEnsureSeedJobs(t *testing.T) {
GetBuild(ConfigureSeedJobsName, gomock.Any()). GetBuild(ConfigureSeedJobsName, gomock.Any()).
Return(&gojenkins.Build{ Return(&gojenkins.Build{
Raw: &gojenkins.BuildResponse{ Raw: &gojenkins.BuildResponse{
Result: string(v1alpha1.BuildSuccessStatus), Result: string(v1alpha2.BuildSuccessStatus),
}, },
}, nil) }, nil)
} }
@ -99,28 +99,28 @@ func TestEnsureSeedJobs(t *testing.T) {
// first run - should create job and schedule build // first run - should create job and schedule build
if reconcileAttempt == 1 { if reconcileAttempt == 1 {
assert.False(t, done) assert.False(t, done)
assert.Equal(t, string(v1alpha1.BuildRunningStatus), string(build.Status)) assert.Equal(t, string(v1alpha2.BuildRunningStatus), string(build.Status))
} }
// second run - should update and finish job // second run - should update and finish job
if reconcileAttempt == 2 { if reconcileAttempt == 2 {
assert.True(t, done) assert.True(t, done)
assert.Equal(t, string(v1alpha1.BuildSuccessStatus), string(build.Status)) assert.Equal(t, string(v1alpha2.BuildSuccessStatus), string(build.Status))
} }
} }
} }
func jenkinsCustomResource() *v1alpha1.Jenkins { func jenkinsCustomResource() *v1alpha2.Jenkins {
return &v1alpha1.Jenkins{ return &v1alpha2.Jenkins{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: "jenkins", Name: "jenkins",
Namespace: "default", Namespace: "default",
}, },
Spec: v1alpha1.JenkinsSpec{ Spec: v1alpha2.JenkinsSpec{
Master: v1alpha1.JenkinsMaster{ Master: v1alpha2.JenkinsMaster{
Annotations: map[string]string{"test": "label"}, Annotations: map[string]string{"test": "label"},
Container: v1alpha1.Container{ Container: v1alpha2.Container{
Image: "jenkins/jenkins", Image: "jenkins/jenkins",
Resources: corev1.ResourceRequirements{ Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{ Requests: corev1.ResourceList{
@ -134,10 +134,10 @@ func jenkinsCustomResource() *v1alpha1.Jenkins {
}, },
}, },
}, },
SeedJobs: []v1alpha1.SeedJob{ SeedJobs: []v1alpha2.SeedJob{
{ {
ID: "jenkins-operator-e2e", ID: "jenkins-operator-e2e",
JenkinsCredentialType: v1alpha1.NoJenkinsCredentialCredentialType, JenkinsCredentialType: v1alpha2.NoJenkinsCredentialCredentialType,
Targets: "cicd/jobs/*.jenkins", Targets: "cicd/jobs/*.jenkins",
Description: "Jenkins Operator e2e tests repository", Description: "Jenkins Operator e2e tests repository",
RepositoryBranch: "master", RepositoryBranch: "master",

View File

@ -7,7 +7,7 @@ import (
"fmt" "fmt"
"strings" "strings"
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha1" "github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2"
"github.com/jenkinsci/kubernetes-operator/pkg/log" "github.com/jenkinsci/kubernetes-operator/pkg/log"
"github.com/go-logr/logr" "github.com/go-logr/logr"
@ -18,7 +18,7 @@ import (
) )
// ValidateSeedJobs verify seed jobs configuration // ValidateSeedJobs verify seed jobs configuration
func (r *SeedJobs) ValidateSeedJobs(jenkins v1alpha1.Jenkins) (bool, error) { func (r *SeedJobs) ValidateSeedJobs(jenkins v1alpha2.Jenkins) (bool, error) {
valid := true valid := true
if !r.validateIfIDIsUnique(jenkins.Spec.SeedJobs) { if !r.validateIfIDIsUnique(jenkins.Spec.SeedJobs) {
@ -48,24 +48,24 @@ func (r *SeedJobs) ValidateSeedJobs(jenkins v1alpha1.Jenkins) (bool, error) {
valid = false valid = false
} }
if _, ok := v1alpha1.AllowedJenkinsCredentialMap[string(seedJob.JenkinsCredentialType)]; !ok { if _, ok := v1alpha2.AllowedJenkinsCredentialMap[string(seedJob.JenkinsCredentialType)]; !ok {
logger.Info("unknown credential type") logger.Info("unknown credential type")
return false, nil return false, nil
} }
if (seedJob.JenkinsCredentialType == v1alpha1.BasicSSHCredentialType || if (seedJob.JenkinsCredentialType == v1alpha2.BasicSSHCredentialType ||
seedJob.JenkinsCredentialType == v1alpha1.UsernamePasswordCredentialType) && len(seedJob.CredentialID) == 0 { seedJob.JenkinsCredentialType == v1alpha2.UsernamePasswordCredentialType) && len(seedJob.CredentialID) == 0 {
logger.Info("credential ID can't be empty") logger.Info("credential ID can't be empty")
valid = false valid = false
} }
// validate repository url match private key // validate repository url match private key
if strings.Contains(seedJob.RepositoryURL, "git@") && seedJob.JenkinsCredentialType == v1alpha1.NoJenkinsCredentialCredentialType { if strings.Contains(seedJob.RepositoryURL, "git@") && seedJob.JenkinsCredentialType == v1alpha2.NoJenkinsCredentialCredentialType {
logger.Info("Jenkins credential must be set while using ssh repository url") logger.Info("Jenkins credential must be set while using ssh repository url")
valid = false valid = false
} }
if seedJob.JenkinsCredentialType == v1alpha1.BasicSSHCredentialType || seedJob.JenkinsCredentialType == v1alpha1.UsernamePasswordCredentialType { if seedJob.JenkinsCredentialType == v1alpha2.BasicSSHCredentialType || seedJob.JenkinsCredentialType == v1alpha2.UsernamePasswordCredentialType {
secret := &v1.Secret{} secret := &v1.Secret{}
namespaceName := types.NamespacedName{Namespace: jenkins.Namespace, Name: seedJob.CredentialID} namespaceName := types.NamespacedName{Namespace: jenkins.Namespace, Name: seedJob.CredentialID}
err := r.k8sClient.Get(context.TODO(), namespaceName, secret) err := r.k8sClient.Get(context.TODO(), namespaceName, secret)
@ -76,12 +76,12 @@ func (r *SeedJobs) ValidateSeedJobs(jenkins v1alpha1.Jenkins) (bool, error) {
return false, stackerr.WithStack(err) return false, stackerr.WithStack(err)
} }
if seedJob.JenkinsCredentialType == v1alpha1.BasicSSHCredentialType { if seedJob.JenkinsCredentialType == v1alpha2.BasicSSHCredentialType {
if ok := validateBasicSSHSecret(logger, *secret); !ok { if ok := validateBasicSSHSecret(logger, *secret); !ok {
valid = false valid = false
} }
} }
if seedJob.JenkinsCredentialType == v1alpha1.UsernamePasswordCredentialType { if seedJob.JenkinsCredentialType == v1alpha2.UsernamePasswordCredentialType {
if ok := validateUsernamePasswordSecret(logger, *secret); !ok { if ok := validateUsernamePasswordSecret(logger, *secret); !ok {
valid = false valid = false
} }
@ -91,7 +91,7 @@ func (r *SeedJobs) ValidateSeedJobs(jenkins v1alpha1.Jenkins) (bool, error) {
return valid, nil return valid, nil
} }
func (r *SeedJobs) validateIfIDIsUnique(seedJobs []v1alpha1.SeedJob) bool { func (r *SeedJobs) validateIfIDIsUnique(seedJobs []v1alpha2.SeedJob) bool {
ids := map[string]bool{} ids := map[string]bool{}
for _, seedJob := range seedJobs { for _, seedJob := range seedJobs {
if _, found := ids[seedJob.ID]; found { if _, found := ids[seedJob.ID]; found {

View File

@ -4,7 +4,7 @@ import (
"context" "context"
"testing" "testing"
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha1" "github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
@ -57,13 +57,13 @@ func TestValidateSeedJobs(t *testing.T) {
Namespace: "default", Namespace: "default",
} }
t.Run("Valid with public repository and without private key", func(t *testing.T) { t.Run("Valid with public repository and without private key", func(t *testing.T) {
jenkins := v1alpha1.Jenkins{ jenkins := v1alpha2.Jenkins{
Spec: v1alpha1.JenkinsSpec{ Spec: v1alpha2.JenkinsSpec{
SeedJobs: []v1alpha1.SeedJob{ SeedJobs: []v1alpha2.SeedJob{
{ {
ID: "example", ID: "example",
CredentialID: "jenkins-operator-e2e", CredentialID: "jenkins-operator-e2e",
JenkinsCredentialType: v1alpha1.NoJenkinsCredentialCredentialType, JenkinsCredentialType: v1alpha2.NoJenkinsCredentialCredentialType,
Targets: "cicd/jobs/*.jenkins", Targets: "cicd/jobs/*.jenkins",
RepositoryBranch: "master", RepositoryBranch: "master",
RepositoryURL: "https://github.com/jenkinsci/kubernetes-operator.git", RepositoryURL: "https://github.com/jenkinsci/kubernetes-operator.git",
@ -79,11 +79,11 @@ func TestValidateSeedJobs(t *testing.T) {
assert.Equal(t, true, result) assert.Equal(t, true, result)
}) })
t.Run("Invalid without id", func(t *testing.T) { t.Run("Invalid without id", func(t *testing.T) {
jenkins := v1alpha1.Jenkins{ jenkins := v1alpha2.Jenkins{
Spec: v1alpha1.JenkinsSpec{ Spec: v1alpha2.JenkinsSpec{
SeedJobs: []v1alpha1.SeedJob{ SeedJobs: []v1alpha2.SeedJob{
{ {
JenkinsCredentialType: v1alpha1.NoJenkinsCredentialCredentialType, JenkinsCredentialType: v1alpha2.NoJenkinsCredentialCredentialType,
Targets: "cicd/jobs/*.jenkins", Targets: "cicd/jobs/*.jenkins",
RepositoryBranch: "master", RepositoryBranch: "master",
RepositoryURL: "https://github.com/jenkinsci/kubernetes-operator.git", RepositoryURL: "https://github.com/jenkinsci/kubernetes-operator.git",
@ -99,13 +99,13 @@ func TestValidateSeedJobs(t *testing.T) {
assert.Equal(t, false, result) assert.Equal(t, false, result)
}) })
t.Run("Valid with private key and secret", func(t *testing.T) { t.Run("Valid with private key and secret", func(t *testing.T) {
jenkins := v1alpha1.Jenkins{ jenkins := v1alpha2.Jenkins{
Spec: v1alpha1.JenkinsSpec{ Spec: v1alpha2.JenkinsSpec{
SeedJobs: []v1alpha1.SeedJob{ SeedJobs: []v1alpha2.SeedJob{
{ {
ID: "example", ID: "example",
CredentialID: "deploy-keys", CredentialID: "deploy-keys",
JenkinsCredentialType: v1alpha1.BasicSSHCredentialType, JenkinsCredentialType: v1alpha2.BasicSSHCredentialType,
Targets: "cicd/jobs/*.jenkins", Targets: "cicd/jobs/*.jenkins",
RepositoryBranch: "master", RepositoryBranch: "master",
RepositoryURL: "https://github.com/jenkinsci/kubernetes-operator.git", RepositoryURL: "https://github.com/jenkinsci/kubernetes-operator.git",
@ -132,13 +132,13 @@ func TestValidateSeedJobs(t *testing.T) {
assert.Equal(t, true, result) assert.Equal(t, true, result)
}) })
t.Run("Invalid private key in secret", func(t *testing.T) { t.Run("Invalid private key in secret", func(t *testing.T) {
jenkins := v1alpha1.Jenkins{ jenkins := v1alpha2.Jenkins{
Spec: v1alpha1.JenkinsSpec{ Spec: v1alpha2.JenkinsSpec{
SeedJobs: []v1alpha1.SeedJob{ SeedJobs: []v1alpha2.SeedJob{
{ {
ID: "example", ID: "example",
CredentialID: "deploy-keys", CredentialID: "deploy-keys",
JenkinsCredentialType: v1alpha1.BasicSSHCredentialType, JenkinsCredentialType: v1alpha2.BasicSSHCredentialType,
Targets: "cicd/jobs/*.jenkins", Targets: "cicd/jobs/*.jenkins",
RepositoryBranch: "master", RepositoryBranch: "master",
RepositoryURL: "https://github.com/jenkinsci/kubernetes-operator.git", RepositoryURL: "https://github.com/jenkinsci/kubernetes-operator.git",
@ -165,13 +165,13 @@ func TestValidateSeedJobs(t *testing.T) {
assert.Equal(t, false, result) assert.Equal(t, false, result)
}) })
t.Run("Invalid with PrivateKey and empty Secret data", func(t *testing.T) { t.Run("Invalid with PrivateKey and empty Secret data", func(t *testing.T) {
jenkins := v1alpha1.Jenkins{ jenkins := v1alpha2.Jenkins{
Spec: v1alpha1.JenkinsSpec{ Spec: v1alpha2.JenkinsSpec{
SeedJobs: []v1alpha1.SeedJob{ SeedJobs: []v1alpha2.SeedJob{
{ {
ID: "example", ID: "example",
CredentialID: "deploy-keys", CredentialID: "deploy-keys",
JenkinsCredentialType: v1alpha1.BasicSSHCredentialType, JenkinsCredentialType: v1alpha2.BasicSSHCredentialType,
Targets: "cicd/jobs/*.jenkins", Targets: "cicd/jobs/*.jenkins",
RepositoryBranch: "master", RepositoryBranch: "master",
RepositoryURL: "https://github.com/jenkinsci/kubernetes-operator.git", RepositoryURL: "https://github.com/jenkinsci/kubernetes-operator.git",
@ -198,13 +198,13 @@ func TestValidateSeedJobs(t *testing.T) {
assert.Equal(t, false, result) assert.Equal(t, false, result)
}) })
t.Run("Invalid with ssh RepositoryURL and empty PrivateKey", func(t *testing.T) { t.Run("Invalid with ssh RepositoryURL and empty PrivateKey", func(t *testing.T) {
jenkins := v1alpha1.Jenkins{ jenkins := v1alpha2.Jenkins{
Spec: v1alpha1.JenkinsSpec{ Spec: v1alpha2.JenkinsSpec{
SeedJobs: []v1alpha1.SeedJob{ SeedJobs: []v1alpha2.SeedJob{
{ {
ID: "example", ID: "example",
CredentialID: "jenkins-operator-e2e", CredentialID: "jenkins-operator-e2e",
JenkinsCredentialType: v1alpha1.BasicSSHCredentialType, JenkinsCredentialType: v1alpha2.BasicSSHCredentialType,
Targets: "cicd/jobs/*.jenkins", Targets: "cicd/jobs/*.jenkins",
RepositoryBranch: "master", RepositoryBranch: "master",
RepositoryURL: "git@github.com:jenkinsci/kubernetes-operator.git", RepositoryURL: "git@github.com:jenkinsci/kubernetes-operator.git",
@ -220,12 +220,12 @@ func TestValidateSeedJobs(t *testing.T) {
assert.Equal(t, false, result) assert.Equal(t, false, result)
}) })
t.Run("Invalid without targets", func(t *testing.T) { t.Run("Invalid without targets", func(t *testing.T) {
jenkins := v1alpha1.Jenkins{ jenkins := v1alpha2.Jenkins{
Spec: v1alpha1.JenkinsSpec{ Spec: v1alpha2.JenkinsSpec{
SeedJobs: []v1alpha1.SeedJob{ SeedJobs: []v1alpha2.SeedJob{
{ {
ID: "example", ID: "example",
JenkinsCredentialType: v1alpha1.NoJenkinsCredentialCredentialType, JenkinsCredentialType: v1alpha2.NoJenkinsCredentialCredentialType,
RepositoryBranch: "master", RepositoryBranch: "master",
RepositoryURL: "https://github.com/jenkinsci/kubernetes-operator.git", RepositoryURL: "https://github.com/jenkinsci/kubernetes-operator.git",
}, },
@ -240,12 +240,12 @@ func TestValidateSeedJobs(t *testing.T) {
assert.Equal(t, false, result) assert.Equal(t, false, result)
}) })
t.Run("Invalid without repository URL", func(t *testing.T) { t.Run("Invalid without repository URL", func(t *testing.T) {
jenkins := v1alpha1.Jenkins{ jenkins := v1alpha2.Jenkins{
Spec: v1alpha1.JenkinsSpec{ Spec: v1alpha2.JenkinsSpec{
SeedJobs: []v1alpha1.SeedJob{ SeedJobs: []v1alpha2.SeedJob{
{ {
ID: "example", ID: "example",
JenkinsCredentialType: v1alpha1.NoJenkinsCredentialCredentialType, JenkinsCredentialType: v1alpha2.NoJenkinsCredentialCredentialType,
Targets: "cicd/jobs/*.jenkins", Targets: "cicd/jobs/*.jenkins",
RepositoryBranch: "master", RepositoryBranch: "master",
}, },
@ -260,12 +260,12 @@ func TestValidateSeedJobs(t *testing.T) {
assert.Equal(t, false, result) assert.Equal(t, false, result)
}) })
t.Run("Invalid without repository branch", func(t *testing.T) { t.Run("Invalid without repository branch", func(t *testing.T) {
jenkins := v1alpha1.Jenkins{ jenkins := v1alpha2.Jenkins{
Spec: v1alpha1.JenkinsSpec{ Spec: v1alpha2.JenkinsSpec{
SeedJobs: []v1alpha1.SeedJob{ SeedJobs: []v1alpha2.SeedJob{
{ {
ID: "example", ID: "example",
JenkinsCredentialType: v1alpha1.NoJenkinsCredentialCredentialType, JenkinsCredentialType: v1alpha2.NoJenkinsCredentialCredentialType,
Targets: "cicd/jobs/*.jenkins", Targets: "cicd/jobs/*.jenkins",
RepositoryURL: "https://github.com/jenkinsci/kubernetes-operator.git", RepositoryURL: "https://github.com/jenkinsci/kubernetes-operator.git",
}, },
@ -280,13 +280,13 @@ func TestValidateSeedJobs(t *testing.T) {
assert.Equal(t, false, result) assert.Equal(t, false, result)
}) })
t.Run("Valid with username and password", func(t *testing.T) { t.Run("Valid with username and password", func(t *testing.T) {
jenkins := v1alpha1.Jenkins{ jenkins := v1alpha2.Jenkins{
Spec: v1alpha1.JenkinsSpec{ Spec: v1alpha2.JenkinsSpec{
SeedJobs: []v1alpha1.SeedJob{ SeedJobs: []v1alpha2.SeedJob{
{ {
ID: "example", ID: "example",
CredentialID: "deploy-keys", CredentialID: "deploy-keys",
JenkinsCredentialType: v1alpha1.UsernamePasswordCredentialType, JenkinsCredentialType: v1alpha2.UsernamePasswordCredentialType,
Targets: "cicd/jobs/*.jenkins", Targets: "cicd/jobs/*.jenkins",
RepositoryBranch: "master", RepositoryBranch: "master",
RepositoryURL: "https://github.com/jenkinsci/kubernetes-operator.git", RepositoryURL: "https://github.com/jenkinsci/kubernetes-operator.git",
@ -313,13 +313,13 @@ func TestValidateSeedJobs(t *testing.T) {
assert.Equal(t, true, result) assert.Equal(t, true, result)
}) })
t.Run("Invalid with empty username", func(t *testing.T) { t.Run("Invalid with empty username", func(t *testing.T) {
jenkins := v1alpha1.Jenkins{ jenkins := v1alpha2.Jenkins{
Spec: v1alpha1.JenkinsSpec{ Spec: v1alpha2.JenkinsSpec{
SeedJobs: []v1alpha1.SeedJob{ SeedJobs: []v1alpha2.SeedJob{
{ {
ID: "example", ID: "example",
CredentialID: "deploy-keys", CredentialID: "deploy-keys",
JenkinsCredentialType: v1alpha1.UsernamePasswordCredentialType, JenkinsCredentialType: v1alpha2.UsernamePasswordCredentialType,
Targets: "cicd/jobs/*.jenkins", Targets: "cicd/jobs/*.jenkins",
RepositoryBranch: "master", RepositoryBranch: "master",
RepositoryURL: "https://github.com/jenkinsci/kubernetes-operator.git", RepositoryURL: "https://github.com/jenkinsci/kubernetes-operator.git",
@ -346,13 +346,13 @@ func TestValidateSeedJobs(t *testing.T) {
assert.Equal(t, false, result) assert.Equal(t, false, result)
}) })
t.Run("Invalid with empty password", func(t *testing.T) { t.Run("Invalid with empty password", func(t *testing.T) {
jenkins := v1alpha1.Jenkins{ jenkins := v1alpha2.Jenkins{
Spec: v1alpha1.JenkinsSpec{ Spec: v1alpha2.JenkinsSpec{
SeedJobs: []v1alpha1.SeedJob{ SeedJobs: []v1alpha2.SeedJob{
{ {
ID: "example", ID: "example",
CredentialID: "deploy-keys", CredentialID: "deploy-keys",
JenkinsCredentialType: v1alpha1.UsernamePasswordCredentialType, JenkinsCredentialType: v1alpha2.UsernamePasswordCredentialType,
Targets: "cicd/jobs/*.jenkins", Targets: "cicd/jobs/*.jenkins",
RepositoryBranch: "master", RepositoryBranch: "master",
RepositoryURL: "https://github.com/jenkinsci/kubernetes-operator.git", RepositoryURL: "https://github.com/jenkinsci/kubernetes-operator.git",
@ -379,13 +379,13 @@ func TestValidateSeedJobs(t *testing.T) {
assert.Equal(t, false, result) assert.Equal(t, false, result)
}) })
t.Run("Invalid without username", func(t *testing.T) { t.Run("Invalid without username", func(t *testing.T) {
jenkins := v1alpha1.Jenkins{ jenkins := v1alpha2.Jenkins{
Spec: v1alpha1.JenkinsSpec{ Spec: v1alpha2.JenkinsSpec{
SeedJobs: []v1alpha1.SeedJob{ SeedJobs: []v1alpha2.SeedJob{
{ {
ID: "example", ID: "example",
CredentialID: "deploy-keys", CredentialID: "deploy-keys",
JenkinsCredentialType: v1alpha1.UsernamePasswordCredentialType, JenkinsCredentialType: v1alpha2.UsernamePasswordCredentialType,
Targets: "cicd/jobs/*.jenkins", Targets: "cicd/jobs/*.jenkins",
RepositoryBranch: "master", RepositoryBranch: "master",
RepositoryURL: "https://github.com/jenkinsci/kubernetes-operator.git", RepositoryURL: "https://github.com/jenkinsci/kubernetes-operator.git",
@ -411,13 +411,13 @@ func TestValidateSeedJobs(t *testing.T) {
assert.Equal(t, false, result) assert.Equal(t, false, result)
}) })
t.Run("Invalid without password", func(t *testing.T) { t.Run("Invalid without password", func(t *testing.T) {
jenkins := v1alpha1.Jenkins{ jenkins := v1alpha2.Jenkins{
Spec: v1alpha1.JenkinsSpec{ Spec: v1alpha2.JenkinsSpec{
SeedJobs: []v1alpha1.SeedJob{ SeedJobs: []v1alpha2.SeedJob{
{ {
ID: "example", ID: "example",
CredentialID: "deploy-keys", CredentialID: "deploy-keys",
JenkinsCredentialType: v1alpha1.UsernamePasswordCredentialType, JenkinsCredentialType: v1alpha2.UsernamePasswordCredentialType,
Targets: "cicd/jobs/*.jenkins", Targets: "cicd/jobs/*.jenkins",
RepositoryBranch: "master", RepositoryBranch: "master",
RepositoryURL: "https://github.com/jenkinsci/kubernetes-operator.git", RepositoryURL: "https://github.com/jenkinsci/kubernetes-operator.git",
@ -446,7 +446,7 @@ func TestValidateSeedJobs(t *testing.T) {
func TestValidateIfIDIsUnique(t *testing.T) { func TestValidateIfIDIsUnique(t *testing.T) {
t.Run("happy", func(t *testing.T) { t.Run("happy", func(t *testing.T) {
seedJobs := []v1alpha1.SeedJob{ seedJobs := []v1alpha2.SeedJob{
{ID: "first"}, {ID: "second"}, {ID: "first"}, {ID: "second"},
} }
ctrl := New(nil, nil, logf.ZapLogger(false)) ctrl := New(nil, nil, logf.ZapLogger(false))
@ -454,7 +454,7 @@ func TestValidateIfIDIsUnique(t *testing.T) {
assert.Equal(t, true, got) assert.Equal(t, true, got)
}) })
t.Run("duplicated ids", func(t *testing.T) { t.Run("duplicated ids", func(t *testing.T) {
seedJobs := []v1alpha1.SeedJob{ seedJobs := []v1alpha2.SeedJob{
{ID: "first"}, {ID: "first"}, {ID: "first"}, {ID: "first"},
} }
ctrl := New(nil, nil, logf.ZapLogger(false)) ctrl := New(nil, nil, logf.ZapLogger(false))

View File

@ -1,12 +1,12 @@
package user package user
import ( import (
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha1" "github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2"
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/user/seedjobs" "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/user/seedjobs"
) )
// Validate validates Jenkins CR Spec section // Validate validates Jenkins CR Spec section
func (r *ReconcileUserConfiguration) Validate(jenkins *v1alpha1.Jenkins) (bool, error) { func (r *ReconcileUserConfiguration) Validate(jenkins *v1alpha2.Jenkins) (bool, error) {
seedJobs := seedjobs.New(r.jenkinsClient, r.k8sClient, r.logger) seedJobs := seedjobs.New(r.jenkinsClient, r.k8sClient, r.logger)
return seedJobs.ValidateSeedJobs(*jenkins) return seedJobs.ValidateSeedJobs(*jenkins)
} }

View File

@ -7,7 +7,7 @@ import (
"sort" "sort"
"strings" "strings"
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha1" "github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2"
jenkinsclient "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/client" jenkinsclient "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/client"
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/jobs" "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/jobs"
@ -52,7 +52,7 @@ func (g *Groovy) ConfigureJob() error {
} }
// Ensure executes groovy script and verifies jenkins job status according to reconciliation loop lifecycle // Ensure executes groovy script and verifies jenkins job status according to reconciliation loop lifecycle
func (g *Groovy) Ensure(secretOrConfigMapData map[string]string, jenkins *v1alpha1.Jenkins) (bool, error) { func (g *Groovy) Ensure(secretOrConfigMapData map[string]string, jenkins *v1alpha2.Jenkins) (bool, error) {
jobsClient := jobs.New(g.jenkinsClient, g.k8sClient, g.logger) jobsClient := jobs.New(g.jenkinsClient, g.k8sClient, g.logger)
hash := g.calculateHash(secretOrConfigMapData) hash := g.calculateHash(secretOrConfigMapData)

View File

@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"reflect" "reflect"
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha1" "github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2"
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/constants" "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/constants"
"github.com/jenkinsci/kubernetes-operator/pkg/log" "github.com/jenkinsci/kubernetes-operator/pkg/log"
@ -85,7 +85,7 @@ func (e *jenkinsDecorator) Create(evt event.CreateEvent, q workqueue.RateLimitin
} }
func (e *jenkinsDecorator) Update(evt event.UpdateEvent, q workqueue.RateLimitingInterface) { func (e *jenkinsDecorator) Update(evt event.UpdateEvent, q workqueue.RateLimitingInterface) {
if !reflect.DeepEqual(evt.ObjectOld.(*v1alpha1.Jenkins).Spec, evt.ObjectNew.(*v1alpha1.Jenkins).Spec) { if !reflect.DeepEqual(evt.ObjectOld.(*v1alpha2.Jenkins).Spec, evt.ObjectNew.(*v1alpha2.Jenkins).Spec) {
log.Log.WithValues("cr", evt.MetaNew.GetName()).Info( log.Log.WithValues("cr", evt.MetaNew.GetName()).Info(
fmt.Sprintf("%T/%s has been updated", evt.ObjectNew, evt.MetaNew.GetName())) fmt.Sprintf("%T/%s has been updated", evt.ObjectNew, evt.MetaNew.GetName()))
} }

View File

@ -5,7 +5,7 @@ import (
"fmt" "fmt"
"reflect" "reflect"
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha1" "github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2"
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/base" "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/base"
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/user" "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/user"
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/constants" "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/constants"
@ -66,7 +66,7 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error {
// Watch for changes to primary resource Jenkins // Watch for changes to primary resource Jenkins
decorator := jenkinsDecorator{handler: &handler.EnqueueRequestForObject{}} decorator := jenkinsDecorator{handler: &handler.EnqueueRequestForObject{}}
err = c.Watch(&source.Kind{Type: &v1alpha1.Jenkins{}}, &decorator) err = c.Watch(&source.Kind{Type: &v1alpha2.Jenkins{}}, &decorator)
if err != nil { if err != nil {
return errors.WithStack(err) return errors.WithStack(err)
} }
@ -74,7 +74,7 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error {
// Watch for changes to secondary resource Pods and requeue the owner Jenkins // Watch for changes to secondary resource Pods and requeue the owner Jenkins
err = c.Watch(&source.Kind{Type: &corev1.Pod{}}, &handler.EnqueueRequestForOwner{ err = c.Watch(&source.Kind{Type: &corev1.Pod{}}, &handler.EnqueueRequestForOwner{
IsController: true, IsController: true,
OwnerType: &v1alpha1.Jenkins{}, OwnerType: &v1alpha2.Jenkins{},
}) })
if err != nil { if err != nil {
return errors.WithStack(err) return errors.WithStack(err)
@ -127,7 +127,7 @@ func (r *ReconcileJenkins) Reconcile(request reconcile.Request) (reconcile.Resul
func (r *ReconcileJenkins) reconcile(request reconcile.Request, logger logr.Logger) (reconcile.Result, error) { func (r *ReconcileJenkins) reconcile(request reconcile.Request, logger logr.Logger) (reconcile.Result, error) {
// Fetch the Jenkins instance // Fetch the Jenkins instance
jenkins := &v1alpha1.Jenkins{} jenkins := &v1alpha2.Jenkins{}
err := r.client.Get(context.TODO(), request.NamespacedName, jenkins) err := r.client.Get(context.TODO(), request.NamespacedName, jenkins)
if err != nil { if err != nil {
if apierrors.IsNotFound(err) { if apierrors.IsNotFound(err) {
@ -219,7 +219,7 @@ func (r *ReconcileJenkins) buildLogger(jenkinsName string) logr.Logger {
return log.Log.WithValues("cr", jenkinsName) return log.Log.WithValues("cr", jenkinsName)
} }
func (r *ReconcileJenkins) setDefaults(jenkins *v1alpha1.Jenkins, logger logr.Logger) error { func (r *ReconcileJenkins) setDefaults(jenkins *v1alpha2.Jenkins, logger logr.Logger) error {
changed := false changed := false
if len(jenkins.Spec.Master.Image) == 0 { if len(jenkins.Spec.Master.Image) == 0 {
logger.Info("Setting default Jenkins master image: " + constants.DefaultJenkinsMasterImage) logger.Info("Setting default Jenkins master image: " + constants.DefaultJenkinsMasterImage)
@ -295,7 +295,7 @@ func (r *ReconcileJenkins) setDefaults(jenkins *v1alpha1.Jenkins, logger logr.Lo
}, },
} }
} }
if reflect.DeepEqual(jenkins.Spec.Service, v1alpha1.Service{}) { if reflect.DeepEqual(jenkins.Spec.Service, v1alpha2.Service{}) {
logger.Info("Setting default Jenkins master service") logger.Info("Setting default Jenkins master service")
changed = true changed = true
var serviceType corev1.ServiceType var serviceType corev1.ServiceType
@ -306,15 +306,15 @@ func (r *ReconcileJenkins) setDefaults(jenkins *v1alpha1.Jenkins, logger logr.Lo
} else { } else {
serviceType = corev1.ServiceTypeClusterIP serviceType = corev1.ServiceTypeClusterIP
} }
jenkins.Spec.Service = v1alpha1.Service{ jenkins.Spec.Service = v1alpha2.Service{
Type: serviceType, Type: serviceType,
Port: constants.DefaultHTTPPortInt32, Port: constants.DefaultHTTPPortInt32,
} }
} }
if reflect.DeepEqual(jenkins.Spec.SlaveService, v1alpha1.Service{}) { if reflect.DeepEqual(jenkins.Spec.SlaveService, v1alpha2.Service{}) {
logger.Info("Setting default Jenkins slave service") logger.Info("Setting default Jenkins slave service")
changed = true changed = true
jenkins.Spec.SlaveService = v1alpha1.Service{ jenkins.Spec.SlaveService = v1alpha2.Service{
Type: corev1.ServiceTypeClusterIP, Type: corev1.ServiceTypeClusterIP,
Port: constants.DefaultSlavePortInt32, Port: constants.DefaultSlavePortInt32,
} }
@ -331,7 +331,7 @@ func (r *ReconcileJenkins) setDefaults(jenkins *v1alpha1.Jenkins, logger logr.Lo
return nil return nil
} }
func setDefaultsForContainer(jenkins *v1alpha1.Jenkins, containerIndex int, logger logr.Logger) bool { func setDefaultsForContainer(jenkins *v1alpha2.Jenkins, containerIndex int, logger logr.Logger) bool {
changed := false changed := false
if len(jenkins.Spec.Master.Containers[containerIndex].ImagePullPolicy) == 0 { if len(jenkins.Spec.Master.Containers[containerIndex].ImagePullPolicy) == 0 {

View File

@ -5,7 +5,7 @@ import (
"fmt" "fmt"
"strings" "strings"
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha1" "github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2"
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/client" "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/client"
"github.com/jenkinsci/kubernetes-operator/pkg/log" "github.com/jenkinsci/kubernetes-operator/pkg/log"
@ -51,20 +51,20 @@ func New(jenkinsClient client.Jenkins, k8sClient k8s.Client, logger logr.Logger)
// entire state is saved in Jenkins.Status.Builds section // entire state is saved in Jenkins.Status.Builds section
// function return 'true' when build finished successfully or false when reconciliation loop should requeue this function // function return 'true' when build finished successfully or false when reconciliation loop should requeue this function
// preserveStatus determines that build won't be removed from Jenkins.Status.Builds section // preserveStatus determines that build won't be removed from Jenkins.Status.Builds section
func (jobs *Jobs) EnsureBuildJob(jobName, hash string, parameters map[string]string, jenkins *v1alpha1.Jenkins, preserveStatus bool) (done bool, err error) { func (jobs *Jobs) EnsureBuildJob(jobName, hash string, parameters map[string]string, jenkins *v1alpha2.Jenkins, preserveStatus bool) (done bool, err error) {
jobs.logger.V(log.VDebug).Info(fmt.Sprintf("Ensuring build, name:'%s' hash:'%s'", jobName, hash)) jobs.logger.V(log.VDebug).Info(fmt.Sprintf("Ensuring build, name:'%s' hash:'%s'", jobName, hash))
build := jobs.getBuildFromStatus(jobName, hash, jenkins) build := jobs.getBuildFromStatus(jobName, hash, jenkins)
if build != nil { if build != nil {
jobs.logger.V(log.VDebug).Info(fmt.Sprintf("Build exists in status, %+v", build)) jobs.logger.V(log.VDebug).Info(fmt.Sprintf("Build exists in status, %+v", build))
switch build.Status { switch build.Status {
case v1alpha1.BuildSuccessStatus: case v1alpha2.BuildSuccessStatus:
return jobs.ensureSuccessBuild(*build, jenkins, preserveStatus) return jobs.ensureSuccessBuild(*build, jenkins, preserveStatus)
case v1alpha1.BuildRunningStatus: case v1alpha2.BuildRunningStatus:
return jobs.ensureRunningBuild(*build, jenkins, preserveStatus) return jobs.ensureRunningBuild(*build, jenkins, preserveStatus)
case v1alpha1.BuildUnstableStatus, v1alpha1.BuildNotBuildStatus, v1alpha1.BuildFailureStatus, v1alpha1.BuildAbortedStatus: case v1alpha2.BuildUnstableStatus, v1alpha2.BuildNotBuildStatus, v1alpha2.BuildFailureStatus, v1alpha2.BuildAbortedStatus:
return jobs.ensureFailedBuild(*build, jenkins, parameters, preserveStatus) return jobs.ensureFailedBuild(*build, jenkins, parameters, preserveStatus)
case v1alpha1.BuildExpiredStatus: case v1alpha2.BuildExpiredStatus:
return jobs.ensureExpiredBuild(*build, jenkins, preserveStatus) return jobs.ensureExpiredBuild(*build, jenkins, preserveStatus)
default: default:
jobs.logger.V(log.VWarn).Info(fmt.Sprintf("Unexpected build status, %+v", build)) jobs.logger.V(log.VWarn).Info(fmt.Sprintf("Unexpected build status, %+v", build))
@ -74,7 +74,7 @@ func (jobs *Jobs) EnsureBuildJob(jobName, hash string, parameters map[string]str
// build is run first time - build job and update status // build is run first time - build job and update status
created := metav1.Now() created := metav1.Now()
newBuild := v1alpha1.Build{ newBuild := v1alpha2.Build{
JobName: jobName, JobName: jobName,
Hash: hash, Hash: hash,
CreateTime: &created, CreateTime: &created,
@ -82,7 +82,7 @@ func (jobs *Jobs) EnsureBuildJob(jobName, hash string, parameters map[string]str
return jobs.buildJob(newBuild, parameters, jenkins) return jobs.buildJob(newBuild, parameters, jenkins)
} }
func (jobs *Jobs) getBuildFromStatus(jobName string, hash string, jenkins *v1alpha1.Jenkins) *v1alpha1.Build { func (jobs *Jobs) getBuildFromStatus(jobName string, hash string, jenkins *v1alpha2.Jenkins) *v1alpha2.Build {
if jenkins != nil { if jenkins != nil {
builds := jenkins.Status.Builds builds := jenkins.Status.Builds
for _, build := range builds { for _, build := range builds {
@ -94,7 +94,7 @@ func (jobs *Jobs) getBuildFromStatus(jobName string, hash string, jenkins *v1alp
return nil return nil
} }
func (jobs *Jobs) ensureSuccessBuild(build v1alpha1.Build, jenkins *v1alpha1.Jenkins, preserveStatus bool) (bool, error) { func (jobs *Jobs) ensureSuccessBuild(build v1alpha2.Build, jenkins *v1alpha2.Jenkins, preserveStatus bool) (bool, error) {
jobs.logger.V(log.VDebug).Info(fmt.Sprintf("Ensuring success build, %+v", build)) jobs.logger.V(log.VDebug).Info(fmt.Sprintf("Ensuring success build, %+v", build))
if !preserveStatus { if !preserveStatus {
@ -107,7 +107,7 @@ func (jobs *Jobs) ensureSuccessBuild(build v1alpha1.Build, jenkins *v1alpha1.Jen
return true, nil return true, nil
} }
func (jobs *Jobs) ensureRunningBuild(build v1alpha1.Build, jenkins *v1alpha1.Jenkins, preserveStatus bool) (bool, error) { func (jobs *Jobs) ensureRunningBuild(build v1alpha2.Build, jenkins *v1alpha2.Jenkins, preserveStatus bool) (bool, error) {
jobs.logger.V(log.VDebug).Info(fmt.Sprintf("Ensuring running build, %+v", build)) jobs.logger.V(log.VDebug).Info(fmt.Sprintf("Ensuring running build, %+v", build))
// FIXME (antoniaklja) implement build expiration // FIXME (antoniaklja) implement build expiration
@ -121,7 +121,7 @@ func (jobs *Jobs) ensureRunningBuild(build v1alpha1.Build, jenkins *v1alpha1.Jen
} }
if jenkinsBuild.GetResult() != "" { if jenkinsBuild.GetResult() != "" {
build.Status = v1alpha1.BuildStatus(strings.ToLower(jenkinsBuild.GetResult())) build.Status = v1alpha2.BuildStatus(strings.ToLower(jenkinsBuild.GetResult()))
} }
err = jobs.updateBuildStatus(build, jenkins) err = jobs.updateBuildStatus(build, jenkins)
@ -130,13 +130,13 @@ func (jobs *Jobs) ensureRunningBuild(build v1alpha1.Build, jenkins *v1alpha1.Jen
return false, err return false, err
} }
if build.Status == v1alpha1.BuildSuccessStatus { if build.Status == v1alpha2.BuildSuccessStatus {
jobs.logger.Info(fmt.Sprintf("Build finished successfully, %+v", build)) jobs.logger.Info(fmt.Sprintf("Build finished successfully, %+v", build))
return true, nil return true, nil
} }
if build.Status == v1alpha1.BuildFailureStatus || build.Status == v1alpha1.BuildUnstableStatus || if build.Status == v1alpha2.BuildFailureStatus || build.Status == v1alpha2.BuildUnstableStatus ||
build.Status == v1alpha1.BuildNotBuildStatus || build.Status == v1alpha1.BuildAbortedStatus { build.Status == v1alpha2.BuildNotBuildStatus || build.Status == v1alpha2.BuildAbortedStatus {
jobs.logger.V(log.VWarn).Info(fmt.Sprintf("Build failed, %+v", build)) jobs.logger.V(log.VWarn).Info(fmt.Sprintf("Build failed, %+v", build))
return false, ErrorBuildFailed return false, ErrorBuildFailed
} }
@ -144,7 +144,7 @@ func (jobs *Jobs) ensureRunningBuild(build v1alpha1.Build, jenkins *v1alpha1.Jen
return false, nil return false, nil
} }
func (jobs *Jobs) ensureFailedBuild(build v1alpha1.Build, jenkins *v1alpha1.Jenkins, parameters map[string]string, preserveStatus bool) (bool, error) { func (jobs *Jobs) ensureFailedBuild(build v1alpha2.Build, jenkins *v1alpha2.Jenkins, parameters map[string]string, preserveStatus bool) (bool, error) {
jobs.logger.V(log.VDebug).Info(fmt.Sprintf("Ensuring failed build, %+v", build)) jobs.logger.V(log.VDebug).Info(fmt.Sprintf("Ensuring failed build, %+v", build))
if build.Retires < BuildRetires { if build.Retires < BuildRetires {
@ -170,7 +170,7 @@ func (jobs *Jobs) ensureFailedBuild(build v1alpha1.Build, jenkins *v1alpha1.Jenk
return false, ErrorUnrecoverableBuildFailed return false, ErrorUnrecoverableBuildFailed
} }
func (jobs *Jobs) ensureExpiredBuild(build v1alpha1.Build, jenkins *v1alpha1.Jenkins, preserveStatus bool) (bool, error) { func (jobs *Jobs) ensureExpiredBuild(build v1alpha2.Build, jenkins *v1alpha2.Jenkins, preserveStatus bool) (bool, error) {
jobs.logger.V(log.VDebug).Info(fmt.Sprintf("Ensuring expired build, %+v", build)) jobs.logger.V(log.VDebug).Info(fmt.Sprintf("Ensuring expired build, %+v", build))
jenkinsBuild, err := jobs.jenkinsClient.GetBuild(build.JobName, build.Number) jenkinsBuild, err := jobs.jenkinsClient.GetBuild(build.JobName, build.Number)
@ -188,7 +188,7 @@ func (jobs *Jobs) ensureExpiredBuild(build v1alpha1.Build, jenkins *v1alpha1.Jen
return false, errors.WithStack(err) return false, errors.WithStack(err)
} }
if v1alpha1.BuildStatus(jenkinsBuild.GetResult()) != v1alpha1.BuildAbortedStatus { if v1alpha2.BuildStatus(jenkinsBuild.GetResult()) != v1alpha2.BuildAbortedStatus {
return false, ErrorAbortBuildFailed return false, ErrorAbortBuildFailed
} }
@ -210,9 +210,9 @@ func (jobs *Jobs) ensureExpiredBuild(build v1alpha1.Build, jenkins *v1alpha1.Jen
return true, nil return true, nil
} }
func (jobs *Jobs) removeBuildFromStatus(build v1alpha1.Build, jenkins *v1alpha1.Jenkins) error { func (jobs *Jobs) removeBuildFromStatus(build v1alpha2.Build, jenkins *v1alpha2.Jenkins) error {
jobs.logger.V(log.VDebug).Info(fmt.Sprintf("Removing build from status, %+v", build)) jobs.logger.V(log.VDebug).Info(fmt.Sprintf("Removing build from status, %+v", build))
builds := make([]v1alpha1.Build, len(jenkins.Status.Builds)) builds := make([]v1alpha2.Build, len(jenkins.Status.Builds))
for _, existingBuild := range jenkins.Status.Builds { for _, existingBuild := range jenkins.Status.Builds {
if existingBuild.JobName != build.JobName && existingBuild.Hash != build.Hash { if existingBuild.JobName != build.JobName && existingBuild.Hash != build.Hash {
builds = append(builds, existingBuild) builds = append(builds, existingBuild)
@ -227,7 +227,7 @@ func (jobs *Jobs) removeBuildFromStatus(build v1alpha1.Build, jenkins *v1alpha1.
return nil return nil
} }
func (jobs *Jobs) buildJob(build v1alpha1.Build, parameters map[string]string, jenkins *v1alpha1.Jenkins) (bool, error) { func (jobs *Jobs) buildJob(build v1alpha2.Build, parameters map[string]string, jenkins *v1alpha2.Jenkins) (bool, error) {
jobs.logger.Info(fmt.Sprintf("Running job, %+v", build)) jobs.logger.Info(fmt.Sprintf("Running job, %+v", build))
job, err := jobs.jenkinsClient.GetJob(build.JobName) job, err := jobs.jenkinsClient.GetJob(build.JobName)
if err != nil { if err != nil {
@ -243,7 +243,7 @@ func (jobs *Jobs) buildJob(build v1alpha1.Build, parameters map[string]string, j
return false, errors.WithStack(err) return false, errors.WithStack(err)
} }
build.Status = v1alpha1.BuildRunningStatus build.Status = v1alpha2.BuildRunningStatus
build.Number = nextBuildNumber build.Number = nextBuildNumber
err = jobs.updateBuildStatus(build, jenkins) err = jobs.updateBuildStatus(build, jenkins)
@ -254,7 +254,7 @@ func (jobs *Jobs) buildJob(build v1alpha1.Build, parameters map[string]string, j
return false, nil return false, nil
} }
func (jobs *Jobs) updateBuildStatus(build v1alpha1.Build, jenkins *v1alpha1.Jenkins) error { func (jobs *Jobs) updateBuildStatus(build v1alpha2.Build, jenkins *v1alpha2.Jenkins) error {
jobs.logger.V(log.VDebug).Info(fmt.Sprintf("Updating build status, %+v", build)) jobs.logger.V(log.VDebug).Info(fmt.Sprintf("Updating build status, %+v", build))
// get index of existing build from status if exists // get index of existing build from status if exists
buildIndex := -1 buildIndex := -1

View File

@ -7,7 +7,7 @@ import (
"fmt" "fmt"
"testing" "testing"
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha1" "github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2"
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/client" "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/client"
"github.com/bndr/gojenkins" "github.com/bndr/gojenkins"
@ -37,7 +37,7 @@ func TestSuccessEnsureJob(t *testing.T) {
// when // when
jenkins := jenkinsCustomResource() jenkins := jenkinsCustomResource()
fakeClient := fake.NewFakeClient() fakeClient := fake.NewFakeClient()
err := v1alpha1.SchemeBuilder.AddToScheme(scheme.Scheme) err := v1alpha2.SchemeBuilder.AddToScheme(scheme.Scheme)
assert.NoError(t, err) assert.NoError(t, err)
err = fakeClient.Create(ctx, jenkins) err = fakeClient.Create(ctx, jenkins)
assert.NoError(t, err) assert.NoError(t, err)
@ -67,7 +67,7 @@ func TestSuccessEnsureJob(t *testing.T) {
GetBuild(jobName, buildNumber). GetBuild(jobName, buildNumber).
Return(&gojenkins.Build{ Return(&gojenkins.Build{
Raw: &gojenkins.BuildResponse{ Raw: &gojenkins.BuildResponse{
Result: string(v1alpha1.BuildSuccessStatus), Result: string(v1alpha2.BuildSuccessStatus),
}, },
}, nil).AnyTimes() }, nil).AnyTimes()
@ -91,13 +91,13 @@ func TestSuccessEnsureJob(t *testing.T) {
// first run - build should be scheduled and status updated // first run - build should be scheduled and status updated
if reconcileAttempt == 1 { if reconcileAttempt == 1 {
assert.False(t, done) assert.False(t, done)
assert.Equal(t, build.Status, v1alpha1.BuildRunningStatus) assert.Equal(t, build.Status, v1alpha2.BuildRunningStatus)
} }
// second run -job should be success and status updated // second run -job should be success and status updated
if reconcileAttempt == 2 { if reconcileAttempt == 2 {
assert.True(t, done) assert.True(t, done)
assert.Equal(t, build.Status, v1alpha1.BuildSuccessStatus) assert.Equal(t, build.Status, v1alpha2.BuildSuccessStatus)
} }
} }
} }
@ -149,7 +149,7 @@ func TestEnsureJobWithFailedBuild(t *testing.T) {
GetBuild(jobName, int64(1)). GetBuild(jobName, int64(1)).
Return(&gojenkins.Build{ Return(&gojenkins.Build{
Raw: &gojenkins.BuildResponse{ Raw: &gojenkins.BuildResponse{
Result: string(v1alpha1.BuildFailureStatus), Result: string(v1alpha2.BuildFailureStatus),
}, },
}, nil) }, nil)
} }
@ -178,7 +178,7 @@ func TestEnsureJobWithFailedBuild(t *testing.T) {
GetBuild(jobName, int64(2)). GetBuild(jobName, int64(2)).
Return(&gojenkins.Build{ Return(&gojenkins.Build{
Raw: &gojenkins.BuildResponse{ Raw: &gojenkins.BuildResponse{
Result: string(v1alpha1.BuildSuccessStatus), Result: string(v1alpha2.BuildSuccessStatus),
}, },
}, nil) }, nil)
} }
@ -204,7 +204,7 @@ func TestEnsureJobWithFailedBuild(t *testing.T) {
assert.NoError(t, errEnsureBuildJob) assert.NoError(t, errEnsureBuildJob)
assert.False(t, done) assert.False(t, done)
assert.Equal(t, build.Number, int64(1)) assert.Equal(t, build.Number, int64(1))
assert.Equal(t, build.Status, v1alpha1.BuildRunningStatus) assert.Equal(t, build.Status, v1alpha2.BuildRunningStatus)
} }
// second run - build should be failure and status updated // second run - build should be failure and status updated
@ -212,7 +212,7 @@ func TestEnsureJobWithFailedBuild(t *testing.T) {
assert.Error(t, errEnsureBuildJob) assert.Error(t, errEnsureBuildJob)
assert.False(t, done) assert.False(t, done)
assert.Equal(t, build.Number, int64(1)) assert.Equal(t, build.Number, int64(1))
assert.Equal(t, build.Status, v1alpha1.BuildFailureStatus) assert.Equal(t, build.Status, v1alpha2.BuildFailureStatus)
} }
// third run - build should be rescheduled and status updated // third run - build should be rescheduled and status updated
@ -220,7 +220,7 @@ func TestEnsureJobWithFailedBuild(t *testing.T) {
assert.NoError(t, errEnsureBuildJob) assert.NoError(t, errEnsureBuildJob)
assert.False(t, done) assert.False(t, done)
assert.Equal(t, build.Number, int64(2)) assert.Equal(t, build.Number, int64(2))
assert.Equal(t, build.Status, v1alpha1.BuildRunningStatus) assert.Equal(t, build.Status, v1alpha2.BuildRunningStatus)
} }
// fourth run - build should be success and status updated // fourth run - build should be success and status updated
@ -228,7 +228,7 @@ func TestEnsureJobWithFailedBuild(t *testing.T) {
assert.NoError(t, errEnsureBuildJob) assert.NoError(t, errEnsureBuildJob)
assert.True(t, done) assert.True(t, done)
assert.Equal(t, build.Number, int64(2)) assert.Equal(t, build.Number, int64(2))
assert.Equal(t, build.Status, v1alpha1.BuildSuccessStatus) assert.Equal(t, build.Status, v1alpha2.BuildSuccessStatus)
} }
} }
} }
@ -281,7 +281,7 @@ func TestEnsureJobFailedWithMaxRetries(t *testing.T) {
GetBuild(buildName, int64(1)). GetBuild(buildName, int64(1)).
Return(&gojenkins.Build{ Return(&gojenkins.Build{
Raw: &gojenkins.BuildResponse{ Raw: &gojenkins.BuildResponse{
Result: string(v1alpha1.BuildFailureStatus), Result: string(v1alpha2.BuildFailureStatus),
}, },
}, nil) }, nil)
} }
@ -310,7 +310,7 @@ func TestEnsureJobFailedWithMaxRetries(t *testing.T) {
GetBuild(buildName, int64(2)). GetBuild(buildName, int64(2)).
Return(&gojenkins.Build{ Return(&gojenkins.Build{
Raw: &gojenkins.BuildResponse{ Raw: &gojenkins.BuildResponse{
Result: string(v1alpha1.BuildFailureStatus), Result: string(v1alpha2.BuildFailureStatus),
}, },
}, nil) }, nil)
} }
@ -337,7 +337,7 @@ func TestEnsureJobFailedWithMaxRetries(t *testing.T) {
assert.False(t, done) assert.False(t, done)
assert.Equal(t, build.Number, int64(1)) assert.Equal(t, build.Number, int64(1))
assert.Equal(t, build.Retires, 0) assert.Equal(t, build.Retires, 0)
assert.Equal(t, build.Status, v1alpha1.BuildRunningStatus) assert.Equal(t, build.Status, v1alpha2.BuildRunningStatus)
} }
// second run - build should be failure and status updated // second run - build should be failure and status updated
@ -346,7 +346,7 @@ func TestEnsureJobFailedWithMaxRetries(t *testing.T) {
assert.False(t, done) assert.False(t, done)
assert.Equal(t, build.Number, int64(1)) assert.Equal(t, build.Number, int64(1))
assert.Equal(t, build.Retires, 0) assert.Equal(t, build.Retires, 0)
assert.Equal(t, build.Status, v1alpha1.BuildFailureStatus) assert.Equal(t, build.Status, v1alpha2.BuildFailureStatus)
} }
// third run - build should be rescheduled and status updated // third run - build should be rescheduled and status updated
@ -356,7 +356,7 @@ func TestEnsureJobFailedWithMaxRetries(t *testing.T) {
//assert.Equal(t, build.Retires, 1) //assert.Equal(t, build.Retires, 1)
assert.Equal(t, build.Number, int64(2)) assert.Equal(t, build.Number, int64(2))
assert.Equal(t, build.Retires, 1) assert.Equal(t, build.Retires, 1)
assert.Equal(t, build.Status, v1alpha1.BuildRunningStatus) assert.Equal(t, build.Status, v1alpha2.BuildRunningStatus)
} }
// fourth run - build should be failure and status updated // fourth run - build should be failure and status updated
@ -365,7 +365,7 @@ func TestEnsureJobFailedWithMaxRetries(t *testing.T) {
assert.False(t, done) assert.False(t, done)
assert.Equal(t, build.Number, int64(2)) assert.Equal(t, build.Number, int64(2))
assert.Equal(t, build.Retires, 1) assert.Equal(t, build.Retires, 1)
assert.Equal(t, build.Status, v1alpha1.BuildFailureStatus) assert.Equal(t, build.Status, v1alpha2.BuildFailureStatus)
} }
// fifth run - build should be unrecoverable failed and status updated // fifth run - build should be unrecoverable failed and status updated
@ -374,21 +374,21 @@ func TestEnsureJobFailedWithMaxRetries(t *testing.T) {
assert.False(t, done) assert.False(t, done)
assert.Equal(t, build.Number, int64(2)) assert.Equal(t, build.Number, int64(2))
assert.Equal(t, build.Retires, 1) assert.Equal(t, build.Retires, 1)
assert.Equal(t, build.Status, v1alpha1.BuildFailureStatus) assert.Equal(t, build.Status, v1alpha2.BuildFailureStatus)
} }
} }
} }
func jenkinsCustomResource() *v1alpha1.Jenkins { func jenkinsCustomResource() *v1alpha2.Jenkins {
return &v1alpha1.Jenkins{ return &v1alpha2.Jenkins{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: "jenkins", Name: "jenkins",
Namespace: "default", Namespace: "default",
}, },
Spec: v1alpha1.JenkinsSpec{ Spec: v1alpha2.JenkinsSpec{
Master: v1alpha1.JenkinsMaster{ Master: v1alpha2.JenkinsMaster{
Annotations: map[string]string{"test": "label"}, Annotations: map[string]string{"test": "label"},
Container: v1alpha1.Container{ Container: v1alpha2.Container{
Image: "jenkins/jenkins", Image: "jenkins/jenkins",
Resources: corev1.ResourceRequirements{ Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{ Requests: corev1.ResourceList{
@ -402,10 +402,10 @@ func jenkinsCustomResource() *v1alpha1.Jenkins {
}, },
}, },
}, },
SeedJobs: []v1alpha1.SeedJob{ SeedJobs: []v1alpha2.SeedJob{
{ {
ID: "jenkins-operator-e2e", ID: "jenkins-operator-e2e",
JenkinsCredentialType: v1alpha1.NoJenkinsCredentialCredentialType, JenkinsCredentialType: v1alpha2.NoJenkinsCredentialCredentialType,
Targets: "cicd/jobs/*.jenkins", Targets: "cicd/jobs/*.jenkins",
Description: "Jenkins Operator e2e tests repository", Description: "Jenkins Operator e2e tests repository",
RepositoryBranch: "master", RepositoryBranch: "master",

View File

@ -5,7 +5,7 @@ import (
"fmt" "fmt"
"testing" "testing"
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha1" "github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2"
jenkinsclient "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/client" jenkinsclient "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/client"
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/base" "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/base"
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/base/resources" "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/base/resources"
@ -30,10 +30,10 @@ func TestConfiguration(t *testing.T) {
systemMessage := "Configuration as Code integration works!!!" systemMessage := "Configuration as Code integration works!!!"
systemMessageEnvName := "SYSTEM_MESSAGE" systemMessageEnvName := "SYSTEM_MESSAGE"
mySeedJob := seedJobConfig{ mySeedJob := seedJobConfig{
SeedJob: v1alpha1.SeedJob{ SeedJob: v1alpha2.SeedJob{
ID: "jenkins-operator", ID: "jenkins-operator",
CredentialID: "jenkins-operator", CredentialID: "jenkins-operator",
JenkinsCredentialType: v1alpha1.NoJenkinsCredentialCredentialType, JenkinsCredentialType: v1alpha2.NoJenkinsCredentialCredentialType,
Targets: "cicd/jobs/*.jenkins", Targets: "cicd/jobs/*.jenkins",
Description: "Jenkins Operator repository", Description: "Jenkins Operator repository",
RepositoryBranch: "master", RepositoryBranch: "master",
@ -64,7 +64,7 @@ func TestConfiguration(t *testing.T) {
// base // base
createUserConfigurationSecret(t, jenkinsCRName, namespace, systemMessageEnvName, systemMessage) createUserConfigurationSecret(t, jenkinsCRName, namespace, systemMessageEnvName, systemMessage)
createUserConfigurationConfigMap(t, jenkinsCRName, namespace, numberOfExecutors, fmt.Sprintf("${%s}", systemMessageEnvName)) createUserConfigurationConfigMap(t, jenkinsCRName, namespace, numberOfExecutors, fmt.Sprintf("${%s}", systemMessageEnvName))
jenkins := createJenkinsCR(t, jenkinsCRName, namespace, &[]v1alpha1.SeedJob{mySeedJob.SeedJob}, volumes) jenkins := createJenkinsCR(t, jenkinsCRName, namespace, &[]v1alpha2.SeedJob{mySeedJob.SeedJob}, volumes)
createDefaultLimitsForContainersInNamespace(t, namespace) createDefaultLimitsForContainersInNamespace(t, namespace)
createKubernetesCredentialsProviderSecret(t, namespace, mySeedJob) createKubernetesCredentialsProviderSecret(t, namespace, mySeedJob)
waitForJenkinsBaseConfigurationToComplete(t, jenkins) waitForJenkinsBaseConfigurationToComplete(t, jenkins)
@ -153,7 +153,7 @@ func createDefaultLimitsForContainersInNamespace(t *testing.T, namespace string)
} }
} }
func verifyJenkinsMasterPodAttributes(t *testing.T, jenkins *v1alpha1.Jenkins) { func verifyJenkinsMasterPodAttributes(t *testing.T, jenkins *v1alpha2.Jenkins) {
jenkinsPod := getJenkinsMasterPod(t, jenkins) jenkinsPod := getJenkinsMasterPod(t, jenkins)
jenkins = getJenkins(t, jenkins.Namespace, jenkins.Name) jenkins = getJenkins(t, jenkins.Namespace, jenkins.Name)
@ -222,7 +222,7 @@ func verifyContainer(t *testing.T, expected corev1.Container, actual corev1.Cont
} }
} }
func verifyPlugins(t *testing.T, jenkinsClient jenkinsclient.Jenkins, jenkins *v1alpha1.Jenkins) { func verifyPlugins(t *testing.T, jenkinsClient jenkinsclient.Jenkins, jenkins *v1alpha2.Jenkins) {
installedPlugins, err := jenkinsClient.GetPlugins(1) installedPlugins, err := jenkinsClient.GetPlugins(1)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)

View File

@ -4,7 +4,7 @@ import (
"context" "context"
"testing" "testing"
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha1" "github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2"
jenkinsclient "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/client" jenkinsclient "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/client"
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/base/resources" "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/base/resources"
@ -17,8 +17,8 @@ import (
"k8s.io/apimachinery/pkg/util/intstr" "k8s.io/apimachinery/pkg/util/intstr"
) )
func getJenkins(t *testing.T, namespace, name string) *v1alpha1.Jenkins { func getJenkins(t *testing.T, namespace, name string) *v1alpha2.Jenkins {
jenkins := &v1alpha1.Jenkins{} jenkins := &v1alpha2.Jenkins{}
namespaceName := types.NamespacedName{Namespace: namespace, Name: name} namespaceName := types.NamespacedName{Namespace: namespace, Name: name}
if err := framework.Global.Client.Get(context.TODO(), namespaceName, jenkins); err != nil { if err := framework.Global.Client.Get(context.TODO(), namespaceName, jenkins); err != nil {
t.Fatal(err) t.Fatal(err)
@ -27,7 +27,7 @@ func getJenkins(t *testing.T, namespace, name string) *v1alpha1.Jenkins {
return jenkins return jenkins
} }
func getJenkinsMasterPod(t *testing.T, jenkins *v1alpha1.Jenkins) *v1.Pod { func getJenkinsMasterPod(t *testing.T, jenkins *v1alpha2.Jenkins) *v1.Pod {
lo := metav1.ListOptions{ lo := metav1.ListOptions{
LabelSelector: labels.SelectorFromSet(resources.BuildResourceLabels(jenkins)).String(), LabelSelector: labels.SelectorFromSet(resources.BuildResourceLabels(jenkins)).String(),
} }
@ -41,7 +41,7 @@ func getJenkinsMasterPod(t *testing.T, jenkins *v1alpha1.Jenkins) *v1.Pod {
return &podList.Items[0] return &podList.Items[0]
} }
func createJenkinsAPIClient(jenkins *v1alpha1.Jenkins) (jenkinsclient.Jenkins, error) { func createJenkinsAPIClient(jenkins *v1alpha2.Jenkins) (jenkinsclient.Jenkins, error) {
adminSecret := &v1.Secret{} adminSecret := &v1.Secret{}
namespaceName := types.NamespacedName{Namespace: jenkins.Namespace, Name: resources.GetOperatorCredentialsSecretName(jenkins)} namespaceName := types.NamespacedName{Namespace: jenkins.Namespace, Name: resources.GetOperatorCredentialsSecretName(jenkins)}
if err := framework.Global.Client.Get(context.TODO(), namespaceName, adminSecret); err != nil { if err := framework.Global.Client.Get(context.TODO(), namespaceName, adminSecret); err != nil {
@ -60,21 +60,21 @@ func createJenkinsAPIClient(jenkins *v1alpha1.Jenkins) (jenkinsclient.Jenkins, e
) )
} }
func createJenkinsCR(t *testing.T, name, namespace string, seedJob *[]v1alpha1.SeedJob, volumes []corev1.Volume) *v1alpha1.Jenkins { func createJenkinsCR(t *testing.T, name, namespace string, seedJob *[]v1alpha2.SeedJob, volumes []corev1.Volume) *v1alpha2.Jenkins {
var seedJobs []v1alpha1.SeedJob var seedJobs []v1alpha2.SeedJob
if seedJob != nil { if seedJob != nil {
seedJobs = append(seedJobs, *seedJob...) seedJobs = append(seedJobs, *seedJob...)
} }
jenkins := &v1alpha1.Jenkins{ jenkins := &v1alpha2.Jenkins{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: name, Name: name,
Namespace: namespace, Namespace: namespace,
}, },
Spec: v1alpha1.JenkinsSpec{ Spec: v1alpha2.JenkinsSpec{
Master: v1alpha1.JenkinsMaster{ Master: v1alpha2.JenkinsMaster{
Annotations: map[string]string{"test": "label"}, Annotations: map[string]string{"test": "label"},
Container: v1alpha1.Container{ Container: v1alpha2.Container{
Image: "jenkins/jenkins", Image: "jenkins/jenkins",
Env: []v1.EnvVar{ Env: []v1.EnvVar{
{ {
@ -107,7 +107,7 @@ func createJenkinsCR(t *testing.T, name, namespace string, seedJob *[]v1alpha1.S
FailureThreshold: int32(10), FailureThreshold: int32(10),
}, },
}, },
Containers: []v1alpha1.Container{ Containers: []v1alpha2.Container{
{ {
Name: "envoyproxy", Name: "envoyproxy",
Image: "envoyproxy/envoy-alpine", Image: "envoyproxy/envoy-alpine",
@ -132,7 +132,7 @@ func createJenkinsCR(t *testing.T, name, namespace string, seedJob *[]v1alpha1.S
return jenkins return jenkins
} }
func verifyJenkinsAPIConnection(t *testing.T, jenkins *v1alpha1.Jenkins) jenkinsclient.Jenkins { func verifyJenkinsAPIConnection(t *testing.T, jenkins *v1alpha2.Jenkins) jenkinsclient.Jenkins {
client, err := createJenkinsAPIClient(jenkins) client, err := createJenkinsAPIClient(jenkins)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -142,7 +142,7 @@ func verifyJenkinsAPIConnection(t *testing.T, jenkins *v1alpha1.Jenkins) jenkins
return client return client
} }
func restartJenkinsMasterPod(t *testing.T, jenkins *v1alpha1.Jenkins) { func restartJenkinsMasterPod(t *testing.T, jenkins *v1alpha2.Jenkins) {
t.Log("Restarting Jenkins master pod") t.Log("Restarting Jenkins master pod")
jenkinsPod := getJenkinsMasterPod(t, jenkins) jenkinsPod := getJenkinsMasterPod(t, jenkins)
err := framework.Global.Client.Delete(context.TODO(), jenkinsPod) err := framework.Global.Client.Delete(context.TODO(), jenkinsPod)

View File

@ -5,7 +5,7 @@ import (
"testing" "testing"
"github.com/jenkinsci/kubernetes-operator/pkg/apis" "github.com/jenkinsci/kubernetes-operator/pkg/apis"
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha1" "github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2"
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/constants" "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/constants"
f "github.com/operator-framework/operator-sdk/pkg/test" f "github.com/operator-framework/operator-sdk/pkg/test"
@ -35,10 +35,10 @@ func setupTest(t *testing.T) (string, *framework.TestCtx) {
t.Fatalf("could not initialize cluster resources: %v", err) t.Fatalf("could not initialize cluster resources: %v", err)
} }
jenkinsServiceList := &v1alpha1.JenkinsList{ jenkinsServiceList := &v1alpha2.JenkinsList{
TypeMeta: metav1.TypeMeta{ TypeMeta: metav1.TypeMeta{
Kind: v1alpha1.Kind, Kind: v1alpha2.Kind,
APIVersion: v1alpha1.SchemeGroupVersion.String(), APIVersion: v1alpha2.SchemeGroupVersion.String(),
}, },
} }
err = framework.AddToFrameworkScheme(apis.AddToScheme, jenkinsServiceList) err = framework.AddToFrameworkScheme(apis.AddToScheme, jenkinsServiceList)

View File

@ -4,7 +4,7 @@ import (
"context" "context"
"testing" "testing"
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha1" "github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2"
jenkinsclient "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/client" jenkinsclient "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/client"
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/base/resources" "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/base/resources"
@ -86,8 +86,8 @@ func checkIfAuthorizationStrategyUnsecuredIsSet(t *testing.T, jenkinsClient jenk
require.NoError(t, err, logs) require.NoError(t, err, logs)
} }
func checkBaseConfigurationCompleteTimeIsNotSet(t *testing.T, jenkins *v1alpha1.Jenkins) { func checkBaseConfigurationCompleteTimeIsNotSet(t *testing.T, jenkins *v1alpha2.Jenkins) {
jenkinsStatus := &v1alpha1.Jenkins{} jenkinsStatus := &v1alpha2.Jenkins{}
namespaceName := types.NamespacedName{Namespace: jenkins.Namespace, Name: jenkins.Name} namespaceName := types.NamespacedName{Namespace: jenkins.Namespace, Name: jenkins.Name}
err := framework.Global.Client.Get(context.TODO(), namespaceName, jenkinsStatus) err := framework.Global.Client.Get(context.TODO(), namespaceName, jenkinsStatus)
if err != nil { if err != nil {

View File

@ -10,7 +10,7 @@ import (
"time" "time"
"github.com/jenkinsci/kubernetes-operator/internal/try" "github.com/jenkinsci/kubernetes-operator/internal/try"
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha1" "github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2"
jenkinsclient "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/client" jenkinsclient "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/client"
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/user/seedjobs" "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/user/seedjobs"
@ -22,7 +22,7 @@ import (
) )
type seedJobConfig struct { type seedJobConfig struct {
v1alpha1.SeedJob v1alpha2.SeedJob
JobNames []string `json:"jobNames,omitempty"` JobNames []string `json:"jobNames,omitempty"`
Username string `json:"username,omitempty"` Username string `json:"username,omitempty"`
Password string `json:"password,omitempty"` Password string `json:"password,omitempty"`
@ -44,7 +44,7 @@ func TestSeedJobs(t *testing.T) {
defer ctx.Cleanup() defer ctx.Cleanup()
jenkinsCRName := "e2e" jenkinsCRName := "e2e"
var seedJobs []v1alpha1.SeedJob var seedJobs []v1alpha2.SeedJob
// base // base
for _, seedJobConfig := range seedJobsConfig.SeedJobs { for _, seedJobConfig := range seedJobsConfig.SeedJobs {
@ -79,7 +79,7 @@ func loadSeedJobsConfig(t *testing.T) seedJobsConfig {
} }
func createKubernetesCredentialsProviderSecret(t *testing.T, namespace string, config seedJobConfig) { func createKubernetesCredentialsProviderSecret(t *testing.T, namespace string, config seedJobConfig) {
if config.JenkinsCredentialType == v1alpha1.NoJenkinsCredentialCredentialType { if config.JenkinsCredentialType == v1alpha2.NoJenkinsCredentialCredentialType {
return return
} }
@ -108,7 +108,7 @@ func createKubernetesCredentialsProviderSecret(t *testing.T, namespace string, c
func verifyJenkinsSeedJobs(t *testing.T, jenkinsClient jenkinsclient.Jenkins, seedJobs []seedJobConfig) { func verifyJenkinsSeedJobs(t *testing.T, jenkinsClient jenkinsclient.Jenkins, seedJobs []seedJobConfig) {
var err error var err error
for _, seedJob := range seedJobs { for _, seedJob := range seedJobs {
if seedJob.JenkinsCredentialType == v1alpha1.BasicSSHCredentialType || seedJob.JenkinsCredentialType == v1alpha1.UsernamePasswordCredentialType { if seedJob.JenkinsCredentialType == v1alpha2.BasicSSHCredentialType || seedJob.JenkinsCredentialType == v1alpha2.UsernamePasswordCredentialType {
err = verifyIfJenkinsCredentialExists(jenkinsClient, seedJob.CredentialID) err = verifyIfJenkinsCredentialExists(jenkinsClient, seedJob.CredentialID)
assert.NoErrorf(t, err, "Jenkins credential '%s' not created for seed job ID '%s'", seedJob.CredentialID, seedJob.ID) assert.NoErrorf(t, err, "Jenkins credential '%s' not created for seed job ID '%s'", seedJob.CredentialID, seedJob.ID)
} }

View File

@ -7,7 +7,7 @@ import (
"time" "time"
"github.com/jenkinsci/kubernetes-operator/internal/try" "github.com/jenkinsci/kubernetes-operator/internal/try"
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha1" "github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2"
jenkinsclient "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/client" jenkinsclient "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/client"
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/base/resources" "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/base/resources"
@ -27,11 +27,11 @@ var (
) )
// checkConditionFunc is used to check if a condition for the jenkins CR is set // checkConditionFunc is used to check if a condition for the jenkins CR is set
type checkConditionFunc func(*v1alpha1.Jenkins, error) bool type checkConditionFunc func(*v1alpha2.Jenkins, error) bool
func waitForJenkinsBaseConfigurationToComplete(t *testing.T, jenkins *v1alpha1.Jenkins) { func waitForJenkinsBaseConfigurationToComplete(t *testing.T, jenkins *v1alpha2.Jenkins) {
t.Log("Waiting for Jenkins base configuration to complete") t.Log("Waiting for Jenkins base configuration to complete")
_, err := WaitUntilJenkinsConditionSet(retryInterval, 150, jenkins, func(jenkins *v1alpha1.Jenkins, err error) bool { _, err := WaitUntilJenkinsConditionSet(retryInterval, 150, jenkins, func(jenkins *v1alpha2.Jenkins, err error) bool {
t.Logf("Current Jenkins status: '%+v', error '%s'", jenkins.Status, err) t.Logf("Current Jenkins status: '%+v', error '%s'", jenkins.Status, err)
return err == nil && jenkins.Status.BaseConfigurationCompletedTime != nil return err == nil && jenkins.Status.BaseConfigurationCompletedTime != nil
}) })
@ -44,7 +44,7 @@ func waitForJenkinsBaseConfigurationToComplete(t *testing.T, jenkins *v1alpha1.J
assert.NoError(t, err) assert.NoError(t, err)
} }
func waitForRecreateJenkinsMasterPod(t *testing.T, jenkins *v1alpha1.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.BuildResourceLabels(jenkins)).String(),
@ -65,9 +65,9 @@ func waitForRecreateJenkinsMasterPod(t *testing.T, jenkins *v1alpha1.Jenkins) {
t.Log("Jenkins pod has been recreated") t.Log("Jenkins pod has been recreated")
} }
func waitForJenkinsUserConfigurationToComplete(t *testing.T, jenkins *v1alpha1.Jenkins) { func waitForJenkinsUserConfigurationToComplete(t *testing.T, jenkins *v1alpha2.Jenkins) {
t.Log("Waiting for Jenkins user configuration to complete") t.Log("Waiting for Jenkins user configuration to complete")
_, err := WaitUntilJenkinsConditionSet(retryInterval, 70, jenkins, func(jenkins *v1alpha1.Jenkins, err error) bool { _, err := WaitUntilJenkinsConditionSet(retryInterval, 70, jenkins, func(jenkins *v1alpha2.Jenkins, err error) bool {
t.Logf("Current Jenkins status: '%+v', error '%s'", jenkins.Status, err) t.Logf("Current Jenkins status: '%+v', error '%s'", jenkins.Status, err)
return err == nil && jenkins.Status.UserConfigurationCompletedTime != nil return err == nil && jenkins.Status.UserConfigurationCompletedTime != nil
}) })
@ -92,8 +92,8 @@ func waitForJenkinsSafeRestart(t *testing.T, jenkinsClient jenkinsclient.Jenkins
} }
// WaitUntilJenkinsConditionSet retries until the specified condition check becomes true for the jenkins CR // WaitUntilJenkinsConditionSet retries until the specified condition check becomes true for the jenkins CR
func WaitUntilJenkinsConditionSet(retryInterval time.Duration, retries int, jenkins *v1alpha1.Jenkins, checkCondition checkConditionFunc) (*v1alpha1.Jenkins, error) { func WaitUntilJenkinsConditionSet(retryInterval time.Duration, retries int, jenkins *v1alpha2.Jenkins, checkCondition checkConditionFunc) (*v1alpha2.Jenkins, error) {
jenkinsStatus := &v1alpha1.Jenkins{} jenkinsStatus := &v1alpha2.Jenkins{}
err := wait.Poll(retryInterval, time.Duration(retries)*retryInterval, func() (bool, error) { err := wait.Poll(retryInterval, time.Duration(retries)*retryInterval, func() (bool, error) {
namespacedName := types.NamespacedName{Namespace: jenkins.Namespace, Name: jenkins.Name} namespacedName := types.NamespacedName{Namespace: jenkins.Namespace, Name: jenkins.Name}
err := framework.Global.Client.Get(goctx.TODO(), namespacedName, jenkinsStatus) err := framework.Global.Client.Get(goctx.TODO(), namespacedName, jenkinsStatus)