Commit 0386efce authored by Konstantinos Samaras-Tsakiris's avatar Konstantinos Samaras-Tsakiris
Browse files

Merge branch 'remove-route-label' into 'master'

Remove router shard assignment logic, since we're using namespace labels

See merge request !31
parents 304c7307 7a7c9e54
Pipeline #2392641 failed with stages
in 3 minutes and 23 seconds
......@@ -42,13 +42,6 @@ type DrupalSiteSpec struct {
// Environment defines the drupal site environments
// +kubebuilder:validation:Required
Environment `json:"environment"`
// We must set MaxLength to 63 characters as this value is stored in Kubernetes labels and there is limited
// length as mentioned in
// https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#syntax-and-character-set
// +kubebuilder:validation:MaxLength=63
// +optional
AssignedRouterShard string `json:"assignedRouterShard,omitempty"`
}
// Environment defines the environment field in DrupalSite
......
......@@ -23,9 +23,6 @@ spec:
containers:
- args:
- --leader-elect
{{- range .Values.drupalsiteOperator.assignableRouterShards }}
- --assignable-router-shard={{ . }}
{{- end }}
command:
- /manager
image: {{ .Values.image | quote }}
......
......@@ -5,9 +5,9 @@ metadata:
name: drupalsite-operator-manager-role
rules:
- apiGroups:
- apps.openshift.io
- apps
resources:
- deploymentconfigs
- deployments
verbs:
- '*'
- apiGroups:
......
......@@ -18,5 +18,3 @@ resources:
# Operator-specific configuration
drupalsiteOperator:
drupalRuntimeRepo: "https://gitlab.cern.ch/drupal/paas/drupal-runtime.git"
assignableRouterShards:
- apps-shard-1
......@@ -36,12 +36,6 @@ spec:
spec:
description: DrupalSiteSpec defines the desired state of DrupalSite
properties:
assignedRouterShard:
description: We must set MaxLength to 63 characters as this value
is stored in Kubernetes labels and there is limited length as mentioned
in https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#syntax-and-character-set
maxLength: 63
type: string
drupalVersion:
description: DrupalVersion defines the version of the Drupal to install
minLength: 1
......
......@@ -18,13 +18,10 @@ package controllers
import (
"context"
"errors"
"fmt"
"io/ioutil"
"math/rand"
"strconv"
"strings"
"time"
"github.com/asaskevich/govalidator"
"github.com/go-logr/logr"
......@@ -50,7 +47,6 @@ const (
// finalizerStr string that is going to added to every DrupalSite created
finalizerStr = "controller.drupalsite.webservices.cern.ch"
productionEnvironment = "production"
routerShardLabel = "drupal.cern.ch/router-shard"
adminAnnotation = "drupal.cern.ch/admin-custom-edit"
)
......@@ -64,8 +60,6 @@ var (
ImageRecipesRepoRef string
// ClusterName is used in the Route's Host field
ClusterName string
// RouterShards is the list of all router shards available in the cluster - passed as a flag to the operator
RouterShards strFlagList
)
type strFlagList []string
......@@ -105,33 +99,9 @@ func ensureSpecFinalizer(drp *webservicesv1a1.DrupalSite, log logr.Logger) (upda
controllerutil.AddFinalizer(drp, finalizerStr)
update = true
}
update, specErr := assignRouterShard(drp)
switch {
case specErr != nil:
log.Info(specErr.Error())
case update:
log.Info(fmt.Sprintf("Assigned router shard %v to a drupal site", drp.Spec.AssignedRouterShard))
}
return
}
func assignRouterShard(drp *webservicesv1a1.DrupalSite) (update bool, err reconcileError) {
if drp.Spec.AssignedRouterShard != "" {
return false, nil
}
if len(RouterShards) == 0 {
return false, newApplicationError(errors.New("specify a valid list of available router shards with the --assignable-router-shard flag"), ErrInvalidSpec)
}
drp.Spec.AssignedRouterShard = randomStrElement(RouterShards)
return true, nil
}
// randomStrElement returns a random element from the array. Panic if len(list) == 0
func randomStrElement(list []string) string {
r := rand.New(rand.NewSource(time.Now().Unix()))
return list[r.Intn(len(list))]
}
/*
ensureResources ensures the presence of all the resources that the DrupalSite needs to serve content, apart from the ingress Route.
This includes BuildConfigs/ImageStreams, DB, PVC, PHP/Nginx deployment + service, site install job.
......@@ -875,7 +845,6 @@ func routeForDrupalSite(currentobject *routev1.Route, d *webservicesv1a1.DrupalS
}
ls := labelsForDrupalSite(d.Name)
ls["app"] = "drupal"
ls[routerShardLabel] = d.Spec.AssignedRouterShard
env := ""
if d.Spec.Environment.Name != productionEnvironment {
......
......@@ -132,7 +132,6 @@ func initEnv() {
controllers.ImageRecipesRepoRef = "master"
}
controllers.ClusterName = getenvOrDie("CLUSTER_NAME")
flag.Var(&controllers.RouterShards, "assignable-router-shard", "List of available router shards")
ImageRecipesRepoDownload := strings.Trim(runtimeRepo[0], ".git") + "/repository/archive.tar?path=configuration&ref=" + controllers.ImageRecipesRepoRef
directoryName := downloadFile(ImageRecipesRepoDownload, "/tmp/repo.tar")
......
package v1
const (
// DeploymentStatusReasonAnnotation represents the reason for deployment being in a given state
// Used for specifying the reason for cancellation or failure of a deployment
// This is on replication controller set by deployer controller.
DeploymentStatusReasonAnnotation = "openshift.io/deployment.status-reason"
// DeploymentPodAnnotation is an annotation on a deployment (a ReplicationController). The
// annotation value is the name of the deployer Pod which will act upon the ReplicationController
// to implement the deployment behavior.
// This is set on replication controller by deployer controller.
DeploymentPodAnnotation = "openshift.io/deployer-pod.name"
// DeploymentConfigAnnotation is an annotation name used to correlate a deployment with the
// DeploymentConfig on which the deployment is based.
// This is set on replication controller pod template by deployer controller.
DeploymentConfigAnnotation = "openshift.io/deployment-config.name"
// DeploymentCancelledAnnotation indicates that the deployment has been cancelled
// The annotation value does not matter and its mere presence indicates cancellation.
// This is set on replication controller by deployment config controller or oc rollout cancel command.
DeploymentCancelledAnnotation = "openshift.io/deployment.cancelled"
// DeploymentEncodedConfigAnnotation is an annotation name used to retrieve specific encoded
// DeploymentConfig on which a given deployment is based.
// This is set on replication controller by deployer controller.
DeploymentEncodedConfigAnnotation = "openshift.io/encoded-deployment-config"
// DeploymentVersionAnnotation is an annotation on a deployment (a ReplicationController). The
// annotation value is the LatestVersion value of the DeploymentConfig which was the basis for
// the deployment.
// This is set on replication controller pod template by deployment config controller.
DeploymentVersionAnnotation = "openshift.io/deployment-config.latest-version"
// DeployerPodForDeploymentLabel is a label which groups pods related to a
// deployment. The value is a deployment name. The deployer pod and hook pods
// created by the internal strategies will have this label. Custom
// strategies can apply this label to any pods they create, enabling
// platform-provided cancellation and garbage collection support.
// This is set on deployer pod by deployer controller.
DeployerPodForDeploymentLabel = "openshift.io/deployer-pod-for.name"
// DeploymentStatusAnnotation is an annotation name used to retrieve the DeploymentPhase of
// a deployment.
// This is set on replication controller by deployer controller.
DeploymentStatusAnnotation = "openshift.io/deployment.phase"
)
type DeploymentConditionReason string
var (
// ReplicationControllerUpdatedReason is added in a deployment config when one of its replication
// controllers is updated as part of the rollout process.
ReplicationControllerUpdatedReason DeploymentConditionReason = "ReplicationControllerUpdated"
// ReplicationControllerCreateError is added in a deployment config when it cannot create a new replication
// controller.
ReplicationControllerCreateErrorReason DeploymentConditionReason = "ReplicationControllerCreateError"
// ReplicationControllerCreatedReason is added in a deployment config when it creates a new replication
// controller.
NewReplicationControllerCreatedReason DeploymentConditionReason = "NewReplicationControllerCreated"
// NewReplicationControllerAvailableReason is added in a deployment config when its newest replication controller is made
// available ie. the number of new pods that have passed readiness checks and run for at least
// minReadySeconds is at least the minimum available pods that need to run for the deployment config.
NewReplicationControllerAvailableReason DeploymentConditionReason = "NewReplicationControllerAvailable"
// ProgressDeadlineExceededReason is added in a deployment config when its newest replication controller fails to show
// any progress within the given deadline (progressDeadlineSeconds).
ProgressDeadlineExceededReason DeploymentConditionReason = "ProgressDeadlineExceeded"
// DeploymentConfigPausedReason is added in a deployment config when it is paused. Lack of progress shouldn't be
// estimated once a deployment config is paused.
DeploymentConfigPausedReason DeploymentConditionReason = "DeploymentConfigPaused"
// DeploymentConfigResumedReason is added in a deployment config when it is resumed. Useful for not failing accidentally
// deployment configs that paused amidst a rollout.
DeploymentConfigResumedReason DeploymentConditionReason = "DeploymentConfigResumed"
// RolloutCancelledReason is added in a deployment config when its newest rollout was
// interrupted by cancellation.
RolloutCancelledReason DeploymentConditionReason = "RolloutCancelled"
)
// DeploymentStatus describes the possible states a deployment can be in.
type DeploymentStatus string
var (
// DeploymentStatusNew means the deployment has been accepted but not yet acted upon.
DeploymentStatusNew DeploymentStatus = "New"
// DeploymentStatusPending means the deployment been handed over to a deployment strategy,
// but the strategy has not yet declared the deployment to be running.
DeploymentStatusPending DeploymentStatus = "Pending"
// DeploymentStatusRunning means the deployment strategy has reported the deployment as
// being in-progress.
DeploymentStatusRunning DeploymentStatus = "Running"
// DeploymentStatusComplete means the deployment finished without an error.
DeploymentStatusComplete DeploymentStatus = "Complete"
// DeploymentStatusFailed means the deployment finished with an error.
DeploymentStatusFailed DeploymentStatus = "Failed"
)
package v1
// This file contains consts that are not shared between components and set just internally.
// They will likely be removed in (near) future.
const (
// DeployerPodCreatedAtAnnotation is an annotation on a deployment that
// records the time in RFC3339 format of when the deployer pod for this particular
// deployment was created.
// This is set by deployer controller, but not consumed by any command or internally.
// DEPRECATED: will be removed soon
DeployerPodCreatedAtAnnotation = "openshift.io/deployer-pod.created-at"
// DeployerPodStartedAtAnnotation is an annotation on a deployment that
// records the time in RFC3339 format of when the deployer pod for this particular
// deployment was started.
// This is set by deployer controller, but not consumed by any command or internally.
// DEPRECATED: will be removed soon
DeployerPodStartedAtAnnotation = "openshift.io/deployer-pod.started-at"
// DeployerPodCompletedAtAnnotation is an annotation on deployment that records
// the time in RFC3339 format of when the deployer pod finished.
// This is set by deployer controller, but not consumed by any command or internally.
// DEPRECATED: will be removed soon
DeployerPodCompletedAtAnnotation = "openshift.io/deployer-pod.completed-at"
// DesiredReplicasAnnotation represents the desired number of replicas for a
// new deployment.
// This is set by deployer controller, but not consumed by any command or internally.
// DEPRECATED: will be removed soon
DesiredReplicasAnnotation = "kubectl.kubernetes.io/desired-replicas"
// DeploymentAnnotation is an annotation on a deployer Pod. The annotation value is the name
// of the deployment (a ReplicationController) on which the deployer Pod acts.
// This is set by deployer controller and consumed internally and in oc adm top command.
// DEPRECATED: will be removed soon
DeploymentAnnotation = "openshift.io/deployment.name"
)
// +k8s:deepcopy-gen=package,register
// +k8s:conversion-gen=github.com/openshift/origin/pkg/apps/apis/apps
// +k8s:defaulter-gen=TypeMeta
// +k8s:openapi-gen=true
// +groupName=apps.openshift.io
// Package v1 is the v1 version of the API.
package v1
package v1
import (
corev1 "k8s.io/api/core/v1"
extensionsv1beta1 "k8s.io/api/extensions/v1beta1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)
var (
legacyGroupVersion = schema.GroupVersion{Group: "", Version: "v1"}
legacySchemeBuilder = runtime.NewSchemeBuilder(addLegacyKnownTypes, corev1.AddToScheme, extensionsv1beta1.AddToScheme)
DeprecatedInstallWithoutGroup = legacySchemeBuilder.AddToScheme
)
func addLegacyKnownTypes(scheme *runtime.Scheme) error {
types := []runtime.Object{
&DeploymentConfig{},
&DeploymentConfigList{},
&DeploymentConfigRollback{},
&DeploymentRequest{},
&DeploymentLog{},
&DeploymentLogOptions{},
&extensionsv1beta1.Scale{},
}
scheme.AddKnownTypes(legacyGroupVersion, types...)
return nil
}
package v1
import (
corev1 "k8s.io/api/core/v1"
extensionsv1beta1 "k8s.io/api/extensions/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)
var (
GroupName = "apps.openshift.io"
GroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1"}
schemeBuilder = runtime.NewSchemeBuilder(addKnownTypes, corev1.AddToScheme, extensionsv1beta1.AddToScheme)
// Install is a function which adds this version to a scheme
Install = schemeBuilder.AddToScheme
// SchemeGroupVersion generated code relies on this name
// Deprecated
SchemeGroupVersion = GroupVersion
// AddToScheme exists solely to keep the old generators creating valid code
// DEPRECATED
AddToScheme = schemeBuilder.AddToScheme
)
// Resource generated code relies on this being here, but it logically belongs to the group
// DEPRECATED
func Resource(resource string) schema.GroupResource {
return schema.GroupResource{Group: GroupName, Resource: resource}
}
// Adds the list of known types to api.Scheme.
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(GroupVersion,
&DeploymentConfig{},
&DeploymentConfigList{},
&DeploymentConfigRollback{},
&DeploymentRequest{},
&DeploymentLog{},
&DeploymentLogOptions{},
&extensionsv1beta1.Scale{},
)
metav1.AddToGroupVersion(scheme, GroupVersion)
return nil
}
This diff is collapsed.
// +build !ignore_autogenerated
// Code generated by deepcopy-gen. DO NOT EDIT.
package v1
import (
corev1 "k8s.io/api/core/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
intstr "k8s.io/apimachinery/pkg/util/intstr"
)
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *CustomDeploymentStrategyParams) DeepCopyInto(out *CustomDeploymentStrategyParams) {
*out = *in
if in.Environment != nil {
in, out := &in.Environment, &out.Environment
*out = make([]corev1.EnvVar, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
if in.Command != nil {
in, out := &in.Command, &out.Command
*out = make([]string, len(*in))
copy(*out, *in)
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CustomDeploymentStrategyParams.
func (in *CustomDeploymentStrategyParams) DeepCopy() *CustomDeploymentStrategyParams {
if in == nil {
return nil
}
out := new(CustomDeploymentStrategyParams)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *DeploymentCause) DeepCopyInto(out *DeploymentCause) {
*out = *in
if in.ImageTrigger != nil {
in, out := &in.ImageTrigger, &out.ImageTrigger
*out = new(DeploymentCauseImageTrigger)
**out = **in
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DeploymentCause.
func (in *DeploymentCause) DeepCopy() *DeploymentCause {
if in == nil {
return nil
}
out := new(DeploymentCause)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *DeploymentCauseImageTrigger) DeepCopyInto(out *DeploymentCauseImageTrigger) {
*out = *in
out.From = in.From
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DeploymentCauseImageTrigger.
func (in *DeploymentCauseImageTrigger) DeepCopy() *DeploymentCauseImageTrigger {
if in == nil {
return nil
}
out := new(DeploymentCauseImageTrigger)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *DeploymentCondition) DeepCopyInto(out *DeploymentCondition) {
*out = *in
in.LastUpdateTime.DeepCopyInto(&out.LastUpdateTime)
in.LastTransitionTime.DeepCopyInto(&out.LastTransitionTime)
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DeploymentCondition.
func (in *DeploymentCondition) DeepCopy() *DeploymentCondition {
if in == nil {
return nil
}
out := new(DeploymentCondition)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *DeploymentConfig) DeepCopyInto(out *DeploymentConfig) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
in.Spec.DeepCopyInto(&out.Spec)
in.Status.DeepCopyInto(&out.Status)
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DeploymentConfig.
func (in *DeploymentConfig) DeepCopy() *DeploymentConfig {
if in == nil {
return nil
}
out := new(DeploymentConfig)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *DeploymentConfig) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *DeploymentConfigList) DeepCopyInto(out *DeploymentConfigList) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ListMeta.DeepCopyInto(&out.ListMeta)
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]DeploymentConfig, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DeploymentConfigList.
func (in *DeploymentConfigList) DeepCopy() *DeploymentConfigList {
if in == nil {
return nil
}
out := new(DeploymentConfigList)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *DeploymentConfigList) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *DeploymentConfigRollback) DeepCopyInto(out *DeploymentConfigRollback) {
*out = *in
out.TypeMeta = in.TypeMeta
if in.UpdatedAnnotations != nil {
in, out := &in.UpdatedAnnotations, &out.UpdatedAnnotations
*out = make(map[string]string, len(*in))
for key, val := range *in {
(*out)[key] = val
}
}
out.Spec = in.Spec
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DeploymentConfigRollback.
func (in *DeploymentConfigRollback) DeepCopy() *DeploymentConfigRollback {
if in == nil {
return nil
}
out := new(DeploymentConfigRollback)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *DeploymentConfigRollback) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *DeploymentConfigRollbackSpec) DeepCopyInto(out *DeploymentConfigRollbackSpec) {
*out = *in
out.From = in.From
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DeploymentConfigRollbackSpec.
func (in *DeploymentConfigRollbackSpec) DeepCopy() *DeploymentConfigRollbackSpec {
if in == nil {
return nil
}
out := new(DeploymentConfigRollbackSpec)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *DeploymentConfigSpec) DeepCopyInto(out *DeploymentConfigSpec) {
*out = *in
in.Strategy.DeepCopyInto(&out.Strategy)
if in.Triggers != nil {
in, out := &in.Triggers, &out.Triggers