Skip to content

Commit

Permalink
Allow configuring pull policy (with Always by default for nightlies) (
Browse files Browse the repository at this point in the history
#57)

* Add pull policies
* Add configurable pull policies for deployments in Che, Keycloak and Postgres deployments
* `Always` policy by default for `nightly`/`latest` images

Signed-off-by: David Festal <dfestal@redhat.com>
  • Loading branch information
davidfestal authored Jul 26, 2019
1 parent d0f171e commit d887a50
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 11 deletions.
8 changes: 7 additions & 1 deletion pkg/apis/org/v1/che_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
package v1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
Expand All @@ -35,6 +35,8 @@ type CheClusterSpecServer struct {
CheImage string `json:"cheImage"`
// CheImageTag is a tag of an image used in Che deployment
CheImageTag string `json:"cheImageTag"`
// CheImagePullPolicy is the image pull policy used in Che registry deployment: default value is Always
CheImagePullPolicy corev1.PullPolicy `json:"cheImagePullPolicy"`
// CheFlavor is an installation flavor. Can be 'che' - upstream or 'codeready' - CodeReady Workspaces. Defaults to 'che'
CheFlavor string `json:"cheFlavor"`
// CheHost is an env consumer by server. Detected automatically from Che route
Expand Down Expand Up @@ -113,6 +115,8 @@ type CheClusterSpecDB struct {
ChePostgresDb string `json:"chePostgresDb"`
// PostgresImage is an image used in Postgres deployment in format image:tag. Defaults to registry.redhat.io/rhscl/postgresql-96-rhel7 (see pkg/deploy/defaults.go for latest tag)
PostgresImage string `json:"postgresImage"`
// PostgresImagePullPolicy is the image pull policy used in Postgres registry deployment: default value is Always
PostgresImagePullPolicy corev1.PullPolicy `json:"postgresImagePullPolicy"`
}

type CheClusterSpecAuth struct {
Expand Down Expand Up @@ -143,6 +147,8 @@ type CheClusterSpecAuth struct {
OauthSecret string `json:"oAuthSecret"`
// KeycloakImage is image:tag used in Keycloak deployment
KeycloakImage string `json:"identityProviderImage"`
// KeycloakImagePullPolicy is the image pull policy used in Keycloak registry deployment: default value is Always
KeycloakImagePullPolicy corev1.PullPolicy `json:"identityProviderImagePullPolicy"`
}

type CheClusterSpecStorage struct {
Expand Down
10 changes: 6 additions & 4 deletions pkg/controller/che/che_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,10 +486,11 @@ func (r *ReconcileChe) Reconcile(request reconcile.Request) (reconcile.Result, e
return reconcile.Result{Requeue: true, RequeueAfter: time.Second * 1}, err
}

pluginRegistryImage := util.GetValue(instance.Spec.Server.PluginRegistryImage, deploy.DefaultPluginRegistryImage)
result, err := addRegistryDeployment(
"plugin",
util.GetValue(instance.Spec.Server.PluginRegistryImage, deploy.DefaultPluginRegistryImage),
corev1.PullPolicy(util.GetValue(string(instance.Spec.Server.PluginRegistryImagePullPolicy), deploy.DefaultPluginRegistryPullPolicy)),
pluginRegistryImage,
corev1.PullPolicy(util.GetValue(string(instance.Spec.Server.PluginRegistryImagePullPolicy), deploy.DefaultPullPolicyFromDockerImage(pluginRegistryImage))),
util.GetValue(string(instance.Spec.Server.PluginRegistryMemoryLimit), deploy.DefaultPluginRegistryMemoryLimit),
util.GetValue(string(instance.Spec.Server.PluginRegistryMemoryRequest), deploy.DefaultPluginRegistryMemoryRequest),
"/v3/plugins/",
Expand All @@ -512,10 +513,11 @@ func (r *ReconcileChe) Reconcile(request reconcile.Request) (reconcile.Result, e
return reconcile.Result{Requeue: true, RequeueAfter: time.Second * 1}, err
}

devfileRegistryImage := util.GetValue(instance.Spec.Server.DevfileRegistryImage, deploy.DefaultDevfileRegistryImage)
result, err := addRegistryDeployment(
"devfile",
util.GetValue(instance.Spec.Server.DevfileRegistryImage, deploy.DefaultDevfileRegistryImage),
corev1.PullPolicy(util.GetValue(string(instance.Spec.Server.DevfileRegistryImagePullPolicy), deploy.DefaultDevfileRegistryPullPolicy)),
devfileRegistryImage,
corev1.PullPolicy(util.GetValue(string(instance.Spec.Server.PluginRegistryImagePullPolicy), deploy.DefaultPullPolicyFromDockerImage(devfileRegistryImage))),
util.GetValue(string(instance.Spec.Server.DevfileRegistryMemoryLimit), deploy.DefaultDevfileRegistryMemoryLimit),
util.GetValue(string(instance.Spec.Server.DevfileRegistryMemoryRequest), deploy.DefaultDevfileRegistryMemoryRequest),
"/devfiles/",
Expand Down
18 changes: 16 additions & 2 deletions pkg/deploy/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
// REMINDER: when updating versions below, see also pkg/apis/org/v1/che_types.go and deploy/crds/org_v1_che_cr.yaml
package deploy

import (
"strings"
)

const (
DefaultCheServerImageRepo = "eclipse/che-server"
DefaultCodeReadyServerImageRepo = "registry.redhat.io/codeready-workspaces/server-rhel8"
Expand All @@ -27,12 +31,10 @@ const (
DefaultIngressStrategy = "multi-host"
DefaultIngressClass = "nginx"
DefaultPluginRegistryImage = "quay.io/eclipse/che-plugin-registry:7.0.0-rc-4.0"
DefaultPluginRegistryPullPolicy = "Always"
DefaultPluginRegistryMemoryLimit = "32Mi"
DefaultPluginRegistryMemoryRequest = "16Mi"
DefaultCodereadyPluginRegistryUrl = "https://che-plugin-registry.openshift.io"
DefaultDevfileRegistryImage = "quay.io/eclipse/che-devfile-registry:7.0.0-rc-4.0"
DefaultDevfileRegistryPullPolicy = "Always"
DefaultDevfileRegistryMemoryLimit = "32Mi"
DefaultDevfileRegistryMemoryRequest = "16Mi"
DefaultKeycloakAdminUserName = "admin"
Expand All @@ -57,3 +59,15 @@ const (
DefaultSecurityContextFsGroup = "1724"
DefaultSecurityContextRunAsUser = "1724"
)

func DefaultPullPolicyFromDockerImage(dockerImage string) string {
tag := "latest"
parts := strings.Split(dockerImage, ":")
if len(parts) > 1 {
tag = parts[1]
}
if tag == "latest" || tag == "nightly" {
return "Always"
}
return "IfNotPresent"
}
7 changes: 5 additions & 2 deletions pkg/deploy/deployment_che.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func NewCheDeployment(cr *orgv1.CheCluster, cheImage string, cheTag string, cmRe
labels := GetLabels(cr, util.GetValue(cr.Spec.Server.CheFlavor, DefaultCheFlavor))
optionalEnv := true
cheFlavor := util.GetValue(cr.Spec.Server.CheFlavor, DefaultCheFlavor)
cheImageAndTag := cheImage + ":" + cheTag
memRequest := util.GetValue(cr.Spec.Server.ServerMemoryRequest, DefaultServerMemoryRequest)
selfSignedCertEnv := corev1.EnvVar{
Name: "CHE_SELF__SIGNED__CERT",
Expand All @@ -47,6 +48,8 @@ func NewCheDeployment(cr *orgv1.CheCluster, cheImage string, cheTag string, cmRe
}
}
memLimit := util.GetValue(cr.Spec.Server.ServerMemoryLimit, DefaultServerMemoryLimit)
pullPolicy := corev1.PullPolicy(util.GetValue(string(cr.Spec.Server.CheImagePullPolicy), DefaultPullPolicyFromDockerImage(cheImageAndTag)))

cheDeployment := appsv1.Deployment{
TypeMeta: metav1.TypeMeta{
Kind: "Deployment",
Expand All @@ -71,8 +74,8 @@ func NewCheDeployment(cr *orgv1.CheCluster, cheImage string, cheTag string, cmRe
Containers: []corev1.Container{
{
Name: cheFlavor,
ImagePullPolicy: corev1.PullIfNotPresent,
Image: cheImage + ":" + cheTag,
ImagePullPolicy: pullPolicy,
Image: cheImageAndTag,
Ports: []corev1.ContainerPort{
{
Name: "http",
Expand Down
3 changes: 2 additions & 1 deletion pkg/deploy/deployment_keycloak.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func NewKeycloakDeployment(cr *orgv1.CheCluster, keycloakPostgresPassword string
keycloakName := "keycloak"
labels := GetLabels(cr, keycloakName)
keycloakImage := util.GetValue(cr.Spec.Auth.KeycloakImage, DefaultKeycloakImage)
pullPolicy := corev1.PullPolicy(util.GetValue(string(cr.Spec.Auth.KeycloakImagePullPolicy), DefaultPullPolicyFromDockerImage(keycloakImage)))
trustpass := util.GeneratePasswd(12)
jbossDir := "/opt/eap"
if cheFlavor == "che" {
Expand Down Expand Up @@ -246,7 +247,7 @@ func NewKeycloakDeployment(cr *orgv1.CheCluster, keycloakPostgresPassword string
{
Name: keycloakName,
Image: keycloakImage,
ImagePullPolicy: corev1.PullIfNotPresent,
ImagePullPolicy: pullPolicy,
Command: []string{
"/bin/sh",
},
Expand Down
4 changes: 3 additions & 1 deletion pkg/deploy/deployment_postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ func NewPostgresDeployment(cr *orgv1.CheCluster, chePostgresPassword string, isO
chePostgresDb := util.GetValue(cr.Spec.Database.ChePostgresDb, "dbche")
postgresAdminPassword := util.GeneratePasswd(12)
postgresImage := util.GetValue(cr.Spec.Database.PostgresImage, DefaultPostgresImage)
pullPolicy := corev1.PullPolicy(util.GetValue(string(cr.Spec.Database.PostgresImagePullPolicy), DefaultPullPolicyFromDockerImage(postgresImage)))

name := "postgres"
labels := GetLabels(cr, name)
deployment := appsv1.Deployment{
Expand Down Expand Up @@ -61,7 +63,7 @@ func NewPostgresDeployment(cr *orgv1.CheCluster, chePostgresPassword string, isO
{
Name: name,
Image: postgresImage,
ImagePullPolicy: corev1.PullIfNotPresent,
ImagePullPolicy: pullPolicy,
Ports: []corev1.ContainerPort{
{
Name: name,
Expand Down

0 comments on commit d887a50

Please sign in to comment.