understandinf openshift source strategy - openshift

regarding to the BuildConfig YAML code bellow:
source:
git:
ref: TCPuniverse-patch-1
uri: 'https://github.com/TCPuniverse/simple-webapp.git'
type: Git
strategy:
sourceStrategy:
from:
kind: ImageStreamTag
name: 'python:3.6'
namespace: openshift
output:
to:
kind: ImageStreamTag
name: 'tpython-app-1:latest'
shouldn't we see "python:3.6" Image Stream Tag in Build > Images page?
And what does the "namespace: openshift" mean in strategy section?

And what does the "namespace: openshift" mean in strategy section?
It means, https://github.com/TCPuniverse/simple-webapp.git source will build using python:3.6 imagestream tag in openshift project. And the built image would be pushed as tpython-app-1:lates imagestream in the project the buildconfig defined.

Related

How do I use an imagestream from another namespace in openshift?

I have been breaking my head over the following:
I have a set of buildconfigs that build images and create imagestreams for it in the "openshift" namespace. This gives me for example the netclient-userspace imagestream.
krist#MacBook-Pro netmaker % oc get is netclient-userspace
NAME IMAGE REPOSITORY TAGS UPDATED
netclient-userspace image-registry.openshift-image-registry.svc:5000/openshift/netclient-userspace latest About an hour ago
What I have however not been able to figure out is how to use this imagestream in a deployment in a different namespace.
Take for example this:
kind: Pod
apiVersion: v1
metadata:
name: netclient-test
namespace: "kvb-netclient-test"
spec:
containers:
- name: netclient
image: netclient-userspace:latest
When I deploy this I get errors...
Failed to pull image "netclient-userspace:latest": rpc error: code =
Unknown desc = reading manifest latest in
docker.io/library/netclient-userspace: errors: denied: requested
access to the resource is denied unauthorized: authentication required
So openshift goest and looks for the image on dockerhub. It shouldn't. How do I tell openshift to use the imagestream here?
When using an ImageStreamTag for a Deployment image source, you need to use the image.openshift.io/triggers annotation. It instructs OpenShift to replace the image: attribute in a Deployment with the value of an ImageStreamTag (and to redeploy it when the ImageStreamTag changes in the future).
Importantly, note the annotation and the image: ' ' with the explicit space character in the yaml string.
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
image.openshift.io/triggers: '[{"from":{"kind":"ImageStreamTag","name":"content-netclient-userspace:latest","namespace":"openshift"},"fieldPath":"spec.template.spec.containers[?(#.name==\"netclient\")].image"}]'
name: netclient-test
namespace: "kvb-netclient-test"
spec:
...
template:
...
spec:
containers:
- command:
- ...
image: ' '
name: netclient
...
I will also mention that, in order to pull images from different namespaces, it may be required to authorize the Deployment's service account to do so: OpenShift Docs.

How can I use Optional Image Inputs in BuildConfig

As documented in https://docs.openshift.com/container-platform/4.3/builds/creating-build-inputs.html#image-source_creating-build-inputs I have configured an Image source for my BuildConfig:
source:
images:
- from:
kind: ImageStreamTag
name: optional-data-image:latest
paths:
- sourcePath: /.
destinationDir: "image-sources/optional-data-dir"
When I start the above build it fails to start with the below message
Warning BuildConfigInstantiateFailed 6m26s buildconfig-controller error instantiating Build from BuildConfig next/site (0): Build.build.openshift.io "my-build-1" is invalid: [spec.source.images[1].from.name: Required value]
Is there a way to specify an optional Image Input so that if the image does not exist the build to still continue normally?
Your build has failed because you did not specifiy from.
strategy:
type: Source
sourceStrategy:
from:
kind: ImageStreamTag
namespace: openshift
name: 'java:8'

KNative serving is not showing Ready after installing on Openshift

Followed the link - https://docs.openshift.com/container-platform/4.1/serverless/installing-openshift-serverless.html to install KNative Serving on top of Openshift v4.1. After installing all the openshift operators, control plane. member roll etc as given in the link; I expect to see that serving component is running by executing -
C:\Knative installation>oc get knativeserving/knative-serving -n knative-serving --template='{{range .status.conditions}}{{printf "%s=%s\n" .type .status}}{{end}}'
But the above returns nothing. Just returns back the prompt.
Also below are o/p of the get resource command of the serving component -
C:\Knative installation>oc get knativeserving/knative-serving -n knative-serving
NAME VERSION READY REASON
knative-serving
C:\Knative installation>oc get knativeserving/knative-serving -n knative-serving -o yaml
apiVersion: serving.knative.dev/v1alpha1
kind: KnativeServing
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"serving.knative.dev/v1alpha1","kind":"KnativeServing","metadata": {"annotations":{},"name":"knative-serving","namespace":"knative-serving"}}
creationTimestamp: "2020-01-12T10:53:42Z"
generation: 1
name: knative-serving
namespace: knative-serving
resourceVersion: "63660251"
selfLink: /apis/serving.knative.dev/v1alpha1/namespaces/knative-serving/knativeservings/knative-serving
uid: cc4b330f-3529-11ea-83ef-0272cb600f74
What could be wrong? I believe KNative Serving did not install correctly but not sure how to debug. I uninstalled and reinstalled several times but no help.
Also, I thought to proceed and install a service using KNative Serving (ref link https://docs.openshift.com/container-platform/4.1/serverless/getting-started-knative-services.html) but, applying the very first resource shows problem.
service.yaml
apiVersion: serving.knative.dev/v1alpha1
kind: Service
metadata:
name: helloworld-go
namespace: default
spec:
template:
spec:
containers:
- image: gcr.io/knative-samples/helloworld-go
env:
- name: TARGET
value: "Go Sample v1"
Applying service.yaml returns error.
C:\start Knative service> oc apply --filename service.yaml
error: unable to recognize "service.yaml": no matches for kind "Service" in version "serving.knative.dev/v1alpha1"
Any help is appreciated. Thanks.

OpenShift freezes at nextjs build phase with message "Creating an optimized production build ..."

I'm trying the OpenShift Online version with two free evaluation months, my evalution stopped very early : I'm unable to get my app online since in the logs it freezes at te compile phase. Seeams to be a RAM issue, but since I don't have control over the ram, does anyone have suggestions?
These are the logs just before it hangs up:
added 915 packages from 491 contributors and audited 8414 packages in 63.205s
found 0 vulnerabilities
npm timing npm Completed in 63927ms
npm info ok
---> Building in production mode
npm info it worked if it ends with ok
npm info using npm#6.9.0
npm info using node#v10.16.0
npm info lifecycle weally#0.1.0~prebuild: weally#0.1.0
npm info lifecycle weally#0.1.0~build: weally#0.1.0
> weally#0.1.0 build /opt/app-root/src
> next build
Creating an optimized production build ...
The process is running fro three days now, it seams it's doing things because the processor graphs shows ups and downs, the memory is locked at 530Mb
Here's my build config:
kind: BuildConfig
apiVersion: build.openshift.io/v1
metadata:
name: weallynode
namespace: weally
selfLink: /apis/build.openshift.io/v1/namespaces/weally/buildconfigs/weallynode
uid: 8c6cf6ec-aa2d-11e9-9f6f-0a580a810073
resourceVersion: '1319487'
creationTimestamp: '2019-07-19T14:00:21Z'
labels:
app: weallynode
spec:
nodeSelector: null
output:
to:
kind: ImageStreamTag
name: 'weallynode:latest'
resources: {}
successfulBuildsHistoryLimit: 5
failedBuildsHistoryLimit: 2
strategy:
type: Source
sourceStrategy:
from:
kind: ImageStreamTag
namespace: openshift
name: 'nodejs:10'
postCommit: {}
source:
type: Git
git:
uri: 'https://1vu#bitbucket.org/1vu/weally.git'
sourceSecret:
name: weallygit
triggers:
- type: ImageChange
imageChange:
lastTriggeredImageID: >-
image-registry.openshift-image-registry.svc:5000/openshift/nodejs#sha256:9dce2f60b87b2eea351213c3d142716c0a70c894df8b3d2d4425b4933b8f6221
- type: ConfigChange
runPolicy: Serial
status:
lastVersion: 6
Could you check your buildConfig resources section ? Refer Setting Build Resources for more details.
apiVersion: "v1"
kind: "BuildConfig"
metadata:
name: "sample-build"
spec:
resources:
limits:
cpu: "100m"
memory: "256Mi"
If the limits section is configured by specific sizes, then you can change them.
I hope it help you.

Openshift retrieve branch name in jenkinsfile

I have configured webhook on bitbucket server which points to Openshift.
I want to get GIT repo url , git branch etc from webhook payload in my inline jenkinsfile but I dont know how to retrieve them. (Webhook triggers build though).
Is it possible ?
Here is my BuildConfig
apiVersion: build.openshift.io/v1
kind: BuildConfig
metadata:
labels:
application: spring-demo
template: openjdk18-web-basic-s2i
name: spring-demo
spec:
output:
to:
kind: ImageStreamTag
name: 'spring--demo:latest'
runPolicy: Serial
source:
type: None
strategy:
jenkinsPipelineStrategy:
jenkinsfile: |-
pipeline {
agent {
label 'maven'
}
stages {
stage('Build') {
steps{
sh "echo ${env.BRANCH_NAME}" <<<<------------- this is null
}
}
}
}
type: JenkinsPipeline
triggers:
- bitbucket:
secretReference:
name: yoyo
type: Bitbucket
--Thanks.
According to this stack overflow question and some Jenkins documentation, you need to install the git plugin on your Jenkins instance. Then you will have the variable GIT_BRANCH and GIT_URL available to you via ${env.GIT_BRANCH} and ${env.GIT_URL}. Make sure your branch names do not have slashes in them, (ex release/1.2.3) as this confuses a lot of key tools in Jenkins.
Alternatively as a last resort, in a Jenkins scripted pipeline you can set your own environment variables via parameter or defaults (like "master") if you know you won't change your branches often.