resources

package
v0.0.0-...-6241ad3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 3, 2021 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Overview

Package resources contains Kubernetes resources required by Jenkins

Index

Constants

View Source
const (
	NameWithSuffixFormat         = "%s-%s"
	PluginDefinitionFormat       = "%s:%s"
	BuilderDockerfileArg         = "--dockerfile=/dockerfile/Dockerfile"
	BuilderContextDirArg         = "--context=dir://workspace/"
	BuilderNoPushArg             = "--no-push"
	BuilderDestinationArg        = "--destination"
	BuilderDigestFileArg         = "--digest-file=/dev/termination-log"
	BuilderReproducibleArg       = "--reproducible"
	BuilderSuffix                = "builder"
	DockerfileStorageSuffix      = "dockerfile-storage"
	DockerSecretSuffix           = "docker-secret"
	DockerfileNameSuffix         = "dockerfile"
	JenkinsImageBuilderImage     = "quay.io/redhat-developer/openshift-jenkins-image-builder:v1.3.0"
	JenkinsImageBuilderName      = "jenkins-image-builder"
	JenkinsImageDefaultBaseImage = "jenkins/jenkins:lts"
	DefaultImageRegistry         = "image-registry.openshift-image-registry.svc:5000"
	DefaultImageTag              = "latest"
	DockerfileName               = "Dockerfile"
	DockerfileTemplate           = `` /* 184-byte string literal not displayed */

)
View Source
const (
	// OperatorUserName defines username for Jenkins API calls
	OperatorUserName = "jenkins-operator"
	// OperatorCredentialsSecretUserNameKey defines key of username in operator credentials secret
	OperatorCredentialsSecretUserNameKey = "user"
	// OperatorCredentialsSecretPasswordKey defines key of password in operator credentials secret
	OperatorCredentialsSecretPasswordKey = "password"
	// OperatorCredentialsSecretTokenKey defines key of token in operator credentials secret
	OperatorCredentialsSecretTokenKey = "token"
	// OperatorCredentialsSecretTokenCreationKey defines key of token creation time in operator credentials secret
	OperatorCredentialsSecretTokenCreationKey = "tokenCreationTime"
)
View Source
const (
	JenkinsSideCarImageEnvVar = "JENKINS_SIDECAR_IMAGE"
	JenkinsBackupImageEnvVar  = "JENKINS_BACKUP_IMAGE"

	JenkinsMasterContainerName = constants.DefaultJenkinsMasterContainerName
	// JenkinsHomeVolumeName is the Jenkins home volume name
	JenkinsHomeVolumeName = "jenkins-home"

	// JenkinsScriptsVolumePath is a path where are scripts used to configure Jenkins
	JenkinsScriptsVolumePath = jenkinsPath + "/scripts"
	// InitScriptName is the init script name which configures init.groovy.d, scripts and install plugins
	InitScriptName = "init.sh"

	// BasePluginsVolumePath is a path where the base-plugins file is generated
	BasePluginsVolumePath = jenkinsPath + "/" + basePluginsFileName

	ConfigurationAsCodeVolumeName       = "casc-config"
	ConfigurationAsCodeVolumePath       = jenkinsPath + "/configuration-as-code"
	ConfigurationAsCodeSecretVolumeName = "casc-secret"
	ConfigurationAsCodeSecretVolumePath = "/tmp" + "/configuration-as-code-secrets"

	// defaut configmap for jenkins configuration
	JenkinsDefaultConfigMapName = "jenkins-default-configuration"

	// Names of Sidecar and Init Containers
	ConfigSidecarName        = "config"
	ConfigInitContainerName  = "config-init"
	PluginsInitContainerName = "plugins-init"
	BackupSidecarName        = "backup"
	BackupInitContainerName  = "backup-init"
	// Config Sidecar related variables
	JenkinsSCConfigReqURL     = "http://localhost:8080/reload-configuration-as-code/?casc-reload-token=$(POD_NAME)"
	JenkinsSCConfigReqMethod  = "POST"
	JenkinsSCConfigReqRetry   = "10"
	JenkinsSCConfigLabel      = "type"
	JenkinsSCConfigLabelValue = "%s-jenkins-config"
	// Backup Sidecar related variables
	JenkinsBackupVolumeMountName = "backup-pool"
	JenkinsBackupVolumePath      = "/jenkins-backups"
	// Helper scripts related variables
	ScriptsVolumeMountName    = "helper-scripts"
	ScriptsVolumePath         = "/jenkins-operator-scripts"
	QuietDownScriptPath       = ScriptsVolumePath + "/quietdown.sh"
	CancelQuietDownScriptPath = ScriptsVolumePath + "/cancelquietdown.sh"
	RestartScriptPath         = ScriptsVolumePath + "/restart.sh"
	SafeRestartScriptPath     = ScriptsVolumePath + "/saferestart.sh"
	// Common attributes used for Sidecars
	SidecarCPULimit   = "100m"
	SidecarMEMLimit   = "100Mi"
	SidecarCPURequest = "50m"
	SidecarMEMRequest = "50Mi"
)
View Source
const (

	// EmptyAPIGroup short hand for the empty API group while defining policies
	EmptyAPIGroup = ""

	// ImageAPIGroup the openshift api group name for images
	ImageAPIGroup = "image.openshift.io"

	// BuildAPIGroup  the openshift api group name for builds
	BuildAPIGroup = "build.openshift.io"

	// SecurityAPIGroup  the openshift api group name for security
	SecurityAPIGroup = "security.openshift.io"
)
View Source
const (
	DefaultOpenShiftImageRegistryNamespace   = "openshift-image-registry"
	DefaultOpenShiftImageRegistryServiceName = "image-registry"
)
View Source
const (
	DefaultCPURequest    = "50m"
	DefaultMemoryRequest = "50Mi"
	DefaultCPULimit      = "100m"
	DefaultMemoryLimit   = "100Mi"
)
View Source
const (
	ServiceAccountNameAnnotation = "kubernetes.io/service-account.name"
	BuilderServiceAccountName    = "builder"
)
View Source
const JenkinsImageBuilderEnv = "JENKINS_BUILDER_IMAGE"
View Source
const RouteKind = "Route"

RouteKind the kind name for route

View Source
const ServiceKind = "Service"

ServiceKind the kind name for Service

Variables

View Source
var (
	ProxyAPIAvailable = false
	ProxyAPIChecked   = false

	ProxyEnvVars = []corev1.EnvVar{}
	GlobalProxy  = &apiconfigv1.Proxy{}
)
View Source
var (
	RouteAPIAvailable = false
	RouteAPIChecked   = false
)
View Source
var (
	EmptyListOptions = metav1.ListOptions{}
	EmptyGetOptions  = metav1.GetOptions{}
)

Functions

func BuildResourceLabels

func BuildResourceLabels(jenkins *v1alpha2.Jenkins) map[string]string

BuildResourceLabels returns labels for all Kubernetes resources created by operator

func DefaultResourceRequirement

func DefaultResourceRequirement() corev1.ResourceRequirements

func GetBasePluginsVolumeNameConfigMapName

func GetBasePluginsVolumeNameConfigMapName(jenkins *v1alpha2.Jenkins) string

GetBasePluginsVolumeNameConfigMapName returns name of Kubernetes config map used to init configuration

func GetDestinationRepository

func GetDestinationRepository(cr *jenkinsv1alpha2.JenkinsImage) string

GetDestinationRepository returns the destination repository matching To.Repository/To.Name:To.Tag or default to openshift-image-registry if running on openshift or --no-push otherwise

func GetDockerBuilderSecretName

func GetDockerBuilderSecretName(namespace string, clientSet client.Client) (string, error)

GetDockerBuilderSecretName returns the *first* Docker secret used for pushing images into the openshift registry in the current namespace or empty string

func GetDockerfileConfigMapName

func GetDockerfileConfigMapName(cr *jenkinsv1alpha2.JenkinsImage) string

func GetExtraRoleBindingName

func GetExtraRoleBindingName(jenkins *v1alpha2.Jenkins, roleRef rbacv1.RoleRef) string

func GetInitConfigurationConfigMapName

func GetInitConfigurationConfigMapName(jenkins *v1alpha2.Jenkins) string

GetInitConfigurationConfigMapName returns name of Kubernetes config map used to init configuration

func GetJenkinsBackupPVCName

func GetJenkinsBackupPVCName(backupVolumeName string) string

func GetJenkinsBackupPoolName

func GetJenkinsBackupPoolName(backupVolumeName string) string

GetJenkinsDeploymentName returns Jenkins deployment name for given CR

func GetJenkinsContainer

func GetJenkinsContainer(jenkins *v1alpha2.Jenkins, jenkinsContainer v1alpha2.Container, envs []corev1.EnvVar) corev1.Container

func GetJenkinsDeploymentName

func GetJenkinsDeploymentName(jenkins *v1alpha2.Jenkins) string

GetJenkinsDeploymentName returns Jenkins deployment name for given CR

func GetJenkinsHTTPServiceName

func GetJenkinsHTTPServiceName(jenkins *v1alpha2.Jenkins) string

GetJenkinsHTTPServiceName returns Kubernetes service name used for expose Jenkins HTTP endpoint

func GetJenkinsJNLPServiceName

func GetJenkinsJNLPServiceName(jenkins *v1alpha2.Jenkins) string

GetJenkinsJNLPServiceName returns Kubernetes service name used for expose Jenkins JNLP endpoint

func GetJenkinsMasterContainerBaseEnvs

func GetJenkinsMasterContainerBaseEnvs(jenkins *v1alpha2.Jenkins) []corev1.EnvVar

GetJenkinsMasterContainerBaseEnvs returns Jenkins master pod envs required by operator

func GetJenkinsMasterContainerBaseVolumeMounts

func GetJenkinsMasterContainerBaseVolumeMounts(jenkins *v1alpha2.Jenkins, spec *v1alpha2.JenkinsSpec) []corev1.VolumeMount

GetJenkinsMasterContainerBaseVolumeMounts returns Jenkins master pod volume mounts required by operator

func GetJenkinsMasterPodBaseVolumes

func GetJenkinsMasterPodBaseVolumes(jenkins *v1alpha2.Jenkins) []corev1.Volume

GetJenkinsMasterPodBaseVolumes returns Jenkins master pod volumes required by operator

func GetOperatorCredentialsSecretName

func GetOperatorCredentialsSecretName(jenkins *v1alpha2.Jenkins) string

GetOperatorCredentialsSecretName returns name of Kubernetes secret used to store jenkins operator credentials to allow calls to Jenkins API

func GetResourceList

func GetResourceList(cpu string, mem string) corev1.ResourceList

func GetResourceName

func GetResourceName(jenkins *v1alpha2.Jenkins) string

GetResourceName returns name of Kubernetes resource base on Jenkins CR

func GetResourceRequirements

func GetResourceRequirements(cpuRequest string, memRequest string, cpuLimit string, memLimit string) corev1.ResourceRequirements

func GetTCPContainerPort

func GetTCPContainerPort(portName string, portNumber int32) corev1.ContainerPort

func IsImageRegistryAvailable

func IsImageRegistryAvailable(manager manager.Manager) bool

IsImageRegistryAvailable tells if the openshift image registry is installed and working

func IsImageRegistryAvailableCached

func IsImageRegistryAvailableCached() bool

func IsOpenshiftProxyAPIAvailable

func IsOpenshiftProxyAPIAvailable(clientSet *kubernetes.Clientset) bool

func IsProxyOverridden

func IsProxyOverridden(envVar []corev1.EnvVar) (overrides bool)

IsOverridden returns true if the given container overrides proxy env variable(s). We apply the following rule:

If a container already defines any of the proxy env variable then it
overrides all of these.

func IsRouteAPIAvailable

func IsRouteAPIAvailable(clientSet *kubernetes.Clientset) bool

IsRouteAPIAvailable tells if the Route API is installed and discoverable

func NewBasePluginConfigMap

func NewBasePluginConfigMap(meta metav1.ObjectMeta, jenkins *v1alpha2.Jenkins) (*corev1.ConfigMap, error)

NewBasePluginConfigMap builds Kubernetes config map used for base plugins

func NewBuilderPod

func NewBuilderPod(client client.Client, cr *jenkinsv1alpha2.JenkinsImage) *corev1.Pod

NewBuilderPod returns a busybox pod with the same name/namespace as the cr.

func NewDefaultPolicyRules

func NewDefaultPolicyRules() []v1.PolicyRule

NewDefaultPolicyRules sets the default policy rules

func NewDockerfileConfigMap

func NewDockerfileConfigMap(cr *jenkinsv1alpha2.JenkinsImage) *corev1.ConfigMap

NewDockerfileConfigMap returns a busybox pod with the same name/namespace as the cr.

func NewInitConfigurationConfigMap

func NewInitConfigurationConfigMap(meta metav1.ObjectMeta, jenkins *v1alpha2.Jenkins) (*corev1.ConfigMap, error)

NewInitConfigurationConfigMap builds Kubernetes config map used to init configuration

func NewJenkinsBackupContainer

func NewJenkinsBackupContainer(jenkins *v1alpha2.Jenkins) corev1.Container

func NewJenkinsBackupInitContainer

func NewJenkinsBackupInitContainer(spec *v1alpha2.JenkinsSpec) corev1.Container

NewJenkinsConfigInitContainer returns Jenkins init container to copy configmap to make it writable

func NewJenkinsConfigContainer

func NewJenkinsConfigContainer(jenkins *v1alpha2.Jenkins) corev1.Container

NewJenkinsConfigContainer returns Jenkins side container for config reloading

func NewJenkinsConfigInitContainer

func NewJenkinsConfigInitContainer(spec *v1alpha2.JenkinsSpec) corev1.Container

NewJenkinsConfigInitContainer returns Jenkins init container to copy configmap to make it writable

func NewJenkinsDeployment

func NewJenkinsDeployment(objectMeta metav1.ObjectMeta, jenkins *v1alpha2.Jenkins, jenkinsSpec *v1alpha2.JenkinsSpec) *appsv1.Deployment

NewJenkinsMasterPod builds Jenkins Master Kubernetes Pod resource.

func NewJenkinsMasterContainer

func NewJenkinsMasterContainer(jenkins *v1alpha2.Jenkins) corev1.Container

NewJenkinsMasterContainer returns Jenkins master Kubernetes container

func NewJenkinsPluginsInitContainer

func NewJenkinsPluginsInitContainer(spec *v1alpha2.JenkinsSpec) corev1.Container

NewJenkinsPluginsInitContainer returns Jenkins init container to install required based plugins

func NewOperatorCredentialsSecret

func NewOperatorCredentialsSecret(meta metav1.ObjectMeta, jenkins *v1alpha2.Jenkins) *corev1.Secret

NewOperatorCredentialsSecret builds the Kubernetes secret used to store jenkins operator credentials to allow calls to Jenkins API

func NewPolicyRule

func NewPolicyRule(apiGroup string, resource, resourceName string, verbs []string) v1.PolicyRule

NewPolicyRule returns a policyRule allowing verbs on resources

func NewProbe

func NewProbe(uri string, port string, scheme corev1.URIScheme, initialDelaySeconds, timeoutSeconds, failureThreshold int32) *corev1.Probe

func NewResourceObjectMeta

func NewResourceObjectMeta(jenkins *v1alpha2.Jenkins) metav1.ObjectMeta

TODO Remove this meta object stuff and use Jenkins instead NewResourceObjectMeta builds ObjectMeta for all Kubernetes resources created by operator

func NewResourceRequirements

func NewResourceRequirements(cpuRequest, memoryRequest, cpuLimit, memoryLimit string) corev1.ResourceRequirements

func NewRole

func NewRole(jenkins *v1alpha2.Jenkins) *v1.Role

NewRole returns rbac role for jenkins master

func NewRoleBinding

func NewRoleBinding(jenkins *v1alpha2.Jenkins, roleRef v1.RoleRef) *v1.RoleBinding

NewRoleBinding returns rbac role binding for jenkins master

func NewScriptsConfigMap

func NewScriptsConfigMap(meta metav1.ObjectMeta, jenkins *v1alpha2.Jenkins) (*corev1.ConfigMap, error)

NewScriptsConfigMap builds Kubernetes config map used to store scripts

func NewServiceAccount

func NewServiceAccount(meta metav1.ObjectMeta, annotations map[string]string) *v1.ServiceAccount

NewServiceAccount return Kubernetes service account

func NewSimpleProbe

func NewSimpleProbe(uri string, port string, scheme corev1.URIScheme, initialDelaySeconds int32) *corev1.Probe

func QueryProxyConfig

func QueryProxyConfig(manager manager.Manager) error

func ToEnvVar

func ToEnvVar(proxy *apiconfigv1.Proxy) []corev1.EnvVar

func UpdateRoute

func UpdateRoute(actual routev1.Route, jenkins *v1alpha2.Jenkins) routev1.Route

UpdateRoute returns new route matching the service

func UpdateService

func UpdateService(current corev1.Service, desired v1alpha2.Service) corev1.Service

UpdateService returns new service with override fields from config

func WaitForPodIsCompleted

func WaitForPodIsCompleted(k8sClient client.Client, podName, namespace string) error

Poll up to timeout seconds for pod to enter running state. Returns an error if the pod never enters the running state.

func WaitForPodRunning

func WaitForPodRunning(k8sClient client.Client, podName, namespace string, timeout time.Duration) error

Poll up to timeout seconds for pod to enter running state. Returns an error if the pod never enters the running state.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL