Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on create Jenkins with Jenkins Image Ref #33

Open
gascani opened this issue Apr 27, 2021 · 0 comments
Open

Error on create Jenkins with Jenkins Image Ref #33

gascani opened this issue Apr 27, 2021 · 0 comments

Comments

@gascani
Copy link

gascani commented Apr 27, 2021

Hi,
i tried to create a Jenkins instance with a reference to Jenking Image but I've got the error:

WARN	controllers.Jenkins	Container `jenkins` - Invalid image	{"cr": "webapp"}

I'm working on this environmenti:

OpenShift: 4.7.0-0.okd-2021-03-28-152009
Jenkins Operator: 0.7.1

This is my JenkinsImage configuration:

apiVersion: jenkins.io/v1alpha2
kind: JenkinsImage
metadata:
  name: jenkins-test-img
  namespace: devops-jenkins
spec:
  from:
    name: quay.io/redhat-developer/origin-jenkins
  plugins:
    - name: locale
  to:
    name: origin-jenkins-test
    tag: latest

And the Jenkins configuration:

apiVersion: jenkins.io/v1alpha2
kind: Jenkins
metadata: 
  name: webapp
  namespace: devops-jenkins
spec: 
  configurationAsCode: 
    defaultConfig: true
    enableAutoReload: true
    enabled: true
  jenkinsImageRef: jenkins-test-img

This are the log on jenkins-operator:

2021-04-27T12:29:14.929Z	INFO	controllers.Jenkins	Jenkins instance correctly found: 22cc3506-0d2a-4c96-aeae-0b3302c76181	{"jenkins": "devops-jenkins/webapp"}
2021-04-27T12:29:14.935Z	INFO	controllers.Jenkins	Jenkins webapp has a jenkinsImageRef defined: jenkins-test-img	{"cr": "webapp"}
2021-04-27T12:29:14.935Z	INFO	controllers.Jenkins	JenkinsImage found with Status:  {Phase:ImageBuildSuccessful Builds:[{Image: MD5Sum:d41d8cd98f00b204e9800998ecf8427e InstalledPlugins:}]}	{"cr": "webapp"}
2021-04-27T12:29:14.935Z	INFO	controllers.Jenkins	JenkinsImage found with latest build mapping to:  /origin-jenkins-test@	{"cr": "webapp"}
2021-04-27T12:29:14.935Z	INFO	controllers.Jenkins	Setting default Jenkins master image: /origin-jenkins-test@	{"cr": "webapp"}
2021-04-27T12:29:14.935Z	INFO	controllers.Jenkins	Setting default Jenkins readinessProbe	{"cr": "webapp"}
2021-04-27T12:29:14.935Z	INFO	controllers.Jenkins	Setting default Jenkins livenessProbe	{"cr": "webapp"}
2021-04-27T12:29:14.935Z	INFO	controller-jenkins.backup	Setting default Jenkins container JAVA_OPTS environment variable
2021-04-27T12:29:14.935Z	INFO	controller-jenkins.backup	Setting default Jenkins container KUBERNETES_TRUST_CERTIFICATES environment variable
2021-04-27T12:29:14.935Z	INFO	controllers.Jenkins	Setting default operator plugins	{"cr": "webapp"}
2021-04-27T12:29:14.935Z	INFO	controllers.Jenkins	Setting default Jenkins master container resource requirements	{"cr": "webapp"}
2021-04-27T12:29:14.935Z	INFO	controllers.Jenkins	Setting default Jenkins master service	{"cr": "webapp"}
2021-04-27T12:29:14.935Z	INFO	controllers.Jenkins	Setting default Jenkins JNLP service	{"cr": "webapp"}
2021-04-27T12:29:14.935Z	INFO	controllers.Jenkins	jenkins.Roles is nil: Adding default role binding edit	{"cr": "webapp"}
2021-04-27T12:29:14.935Z	INFO	controller-jenkins.backup	Default RoleBinding to add &RoleBinding{ObjectMeta:{jenkins-webapp-cr-edit  devops-jenkins    0 0001-01-01 00:00:00 +0000 UTC <nil> <nil> map[] map[] [] []  []},Subjects:[]Subject{Subject{Kind:ServiceAccount,APIGroup:,Name:jenkins-webapp,Namespace:devops-jenkins,},},RoleRef:RoleRef{APIGroup:rbac.authorization.k8s.io,Kind:ClusterRole,Name:edit,},}
2021-04-27T12:29:14.935Z	INFO	controllers.Jenkins	Comparing current status.Spec	{"cr": "webapp"}
2021-04-27T12:29:14.935Z	DEBUG	controllers.Jenkins	setDefaults reported a change: false	{"cr": "webapp"}
2021-04-27T12:29:14.935Z	DEBUG	controllers.Jenkins	Starting base configuration reconciliation for validation	{"cr": "webapp"}
2021-04-27T12:29:14.935Z	INFO	controller-jenkins	Default config is enabled but Default ConfigMap 'jenkins-default-configuration' is not found, creating Default ConfigMap 
2021-04-27T12:29:14.946Z	WARN	controllers.Jenkins	Validation of base configuration failed, please correct Jenkins CR.	{"cr": "webapp"}
github.com/go-logr/zapr.(*infoLogger).Info
	/go/src/github.com/jenkinsci/kubernetes-operator/vendor/github.com/go-logr/zapr/zapr.go:69
github.com/jenkinsci/jenkins-automation-operator/controllers.(*JenkinsReconciler).reconcile
	/go/src/github.com/jenkinsci/kubernetes-operator/controllers/jenkins_controller.go:400
github.com/jenkinsci/jenkins-automation-operator/controllers.(*JenkinsReconciler).Reconcile
	/go/src/github.com/jenkinsci/kubernetes-operator/controllers/jenkins_controller.go:144
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler
	/go/src/github.com/jenkinsci/kubernetes-operator/vendor/sigs.k8s.io/controller-runtime/pkg/internal/controller/controller.go:256
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem
	/go/src/github.com/jenkinsci/kubernetes-operator/vendor/sigs.k8s.io/controller-runtime/pkg/internal/controller/controller.go:232
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).worker
	/go/src/github.com/jenkinsci/kubernetes-operator/vendor/sigs.k8s.io/controller-runtime/pkg/internal/controller/controller.go:211
k8s.io/apimachinery/pkg/util/wait.JitterUntil.func1
	/go/src/github.com/jenkinsci/kubernetes-operator/vendor/k8s.io/apimachinery/pkg/util/wait/wait.go:152
k8s.io/apimachinery/pkg/util/wait.JitterUntil
	/go/src/github.com/jenkinsci/kubernetes-operator/vendor/k8s.io/apimachinery/pkg/util/wait/wait.go:153
k8s.io/apimachinery/pkg/util/wait.Until
	/go/src/github.com/jenkinsci/kubernetes-operator/vendor/k8s.io/apimachinery/pkg/util/wait/wait.go:88
2021-04-27T12:29:14.946Z	WARN	controllers.Jenkins	Container `jenkins` - Invalid image	{"cr": "webapp"}
github.com/go-logr/zapr.(*infoLogger).Info
	/go/src/github.com/jenkinsci/kubernetes-operator/vendor/github.com/go-logr/zapr/zapr.go:69
github.com/jenkinsci/jenkins-automation-operator/controllers.(*JenkinsReconciler).reconcile
	/go/src/github.com/jenkinsci/kubernetes-operator/controllers/jenkins_controller.go:402
github.com/jenkinsci/jenkins-automation-operator/controllers.(*JenkinsReconciler).Reconcile
	/go/src/github.com/jenkinsci/kubernetes-operator/controllers/jenkins_controller.go:144
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler
	/go/src/github.com/jenkinsci/kubernetes-operator/vendor/sigs.k8s.io/controller-runtime/pkg/internal/controller/controller.go:256
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem
	/go/src/github.com/jenkinsci/kubernetes-operator/vendor/sigs.k8s.io/controller-runtime/pkg/internal/controller/controller.go:232
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).worker
	/go/src/github.com/jenkinsci/kubernetes-operator/vendor/sigs.k8s.io/controller-runtime/pkg/internal/controller/controller.go:211
k8s.io/apimachinery/pkg/util/wait.JitterUntil.func1
	/go/src/github.com/jenkinsci/kubernetes-operator/vendor/k8s.io/apimachinery/pkg/util/wait/wait.go:152
k8s.io/apimachinery/pkg/util/wait.JitterUntil
	/go/src/github.com/jenkinsci/kubernetes-operator/vendor/k8s.io/apimachinery/pkg/util/wait/wait.go:153
k8s.io/apimachinery/pkg/util/wait.Until
	/go/src/github.com/jenkinsci/kubernetes-operator/vendor/k8s.io/apimachinery/pkg/util/wait/wait.go:88
2021-04-27T12:29:14.958Z	INFO	controllers.Jenkins	Reconcile loop success !!!	{"jenkins": "devops-jenkins/webapp"}
2021-04-27T12:29:14.958Z	DEBUG	controller-runtime.controller	Successfully Reconciled	{"controller": "jenkins", "request": "devops-jenkins/webapp"}

The error:

controllers.Jenkins	Container `jenkins` - Invalid image	{"cr": "webapp"}" 

is caused by image name: /origin-jenkins-test@

that does not match expected regex
https://github.com/redhat-developer/jenkins-operator/blob/v0.7.1/controllers/jenkins_controller.go

	if !dockerImageRegexp.MatchString(container.Image) && !docker.ReferenceRegexp.MatchString(container.Image) {
		messages = append(messages, "Invalid image")
	}

Image name is defined in:

https://github.com/redhat-developer/jenkins-operator/blob/v0.7.1/pkg/configuration/base/validate.go

		if jenkinsImage.Status.Phase == v1alpha2.ImageBuildSuccessful {
			// Get the latest build otherwise
			builds := jenkinsImage.Status.Builds
			imageSHA256 := builds[len(builds)-1].Image
			jenkinsMasterImage = fmt.Sprintf("%s/%s@%s", jenkinsImage.Spec.To.Registry, jenkinsImage.Spec.To.Name, imageSHA256)
			logger.Info(fmt.Sprintf("JenkinsImage found with latest build mapping to:  %s", jenkinsMasterImage))
		}

And imageSHA256 is defined froin "Image" in:

https://github.com/redhat-developer/jenkins-operator/blob/main/controllers/jenkinsimage_controller.go

		builtImage := strings.Trim(status.State.Terminated.Message, YamlMultilineDataFieldCutSet)
			r.Log.Info(fmt.Sprintf("Found built image (trimed): %s", builtImage))
			dockerfileContent, _ := r.getDockerfileContent(instance)
			dockerfileMD5 := strings.Trim(fmt.Sprintf("%x", md5.Sum([]byte(dockerfileContent))), YamlMultilineDataFieldCutSet)
			r.Log.Info(fmt.Sprintf("Found image checksum (trimed): %s", dockerfileMD5))
			build := v1alpha2.JenkinsImageBuild{
				MD5Sum: dockerfileMD5,
				Image:  builtImage,
			}

Image is undefined because in the status of my jenkins image builder pod there is no "Message" field in state -> terminated

containerStatuses:
    - restartCount: 0
      started: false
      ready: false
      name: jenkins-image-builder
      state:
        terminated:
          exitCode: 0
          reason: Completed
          startedAt: '2021-04-27T12:24:14Z'
          finishedAt: '2021-04-27T12:24:14Z'
          containerID: >-
            cri-o://3fb788ecf51cee73c5741f3653899b6ddc62d1b179d85344adf1b8a5ec745be9
      imageID: >-
        quay.io/redhat-developer/openshift-jenkins-image-builder@sha256:6f491f7ee7ad18b85589ea22820dbb337544903380e78615737639ab5c8e3f66
      image: >-
        quay.io/redhat-developer/openshift-jenkins-image-builder@sha256:6f491f7ee7ad18b85589ea22820dbb337544903380e78615737639ab5c8e3f66
      lastState: {}
      containerID: 'cri-o://3fb788ecf51cee73c5741f3653899b6ddc62d1b179d85344adf1b8a5ec745be9'
  qosClass: BestEffort

Where did i go wrong?

Thanks,
Giorgio

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant