Commit aab94886 authored by Dimitra Chatzichrysou's avatar Dimitra Chatzichrysou Committed by Vineet Reddy Rajula
Browse files

Support branches for extraConfigRepo

parent b539f653
......@@ -68,11 +68,16 @@ type Version struct {
type Configuration struct {
// ExtraConfigurationRepo injects the composer project and other supported configuration from the given git repo to the site,
// by building an image specific to this site from the generic CERN one.
// Add extra modules to your website with Composer through a Git repo, following these docs
// Add extra modules to your website with Composer through a Git repo.
// This field is deprecated.
// +kubebuilder:validation:Pattern=`[(http(s)?):\/\/(www\.)?a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)`
// +optional
ExtraConfigurationRepo string `json:"extraConfigurationRepo,omitempty"`
// TODO: support branches https://gitlab.cern.ch/drupal/paas/drupalsite-operator/-/issues/28
// ExtraConfigurationRepository injects the composer project and other supported configuration from the given git repo to the site,
// by building an image specific to this site from the generic CERN one.
// +optional
ExtraConfigurationRepository `json:"extraConfigurationRepository,omitempty"`
// QoSClass specifies the website's performance and availability requirements. The default value is "standard".
// +kubebuilder:validation:Enum:=critical;test;standard
......@@ -115,6 +120,15 @@ type Configuration struct {
Easystart string `json:"easystart,omitempty"`
}
// ExtraConfigurationRepository injects the composer project and other supported configuration from a git repository
type ExtraConfigurationRepository struct {
// Branch specifies the branch of the repository
// +kubebuilder:default=master
Branch string `json:"branch,omitempty"`
// RepositoryUrl specifies the URL of the repository
RepositoryUrl Url `json:"repositoryUrl,omitempty"`
}
// QoSClass specifies the website's performance and availability requirements
type QoSClass string
......
......@@ -51,6 +51,7 @@ func (in *Backup) DeepCopy() *Backup {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Configuration) DeepCopyInto(out *Configuration) {
*out = *in
out.ExtraConfigurationRepository = in.ExtraConfigurationRepository
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Configuration.
......@@ -379,6 +380,21 @@ func (in *DrupalVersion) DeepCopy() *DrupalVersion {
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ExtraConfigurationRepository) DeepCopyInto(out *ExtraConfigurationRepository) {
*out = *in
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ExtraConfigurationRepository.
func (in *ExtraConfigurationRepository) DeepCopy() *ExtraConfigurationRepository {
if in == nil {
return nil
}
out := new(ExtraConfigurationRepository)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ReleaseID) DeepCopyInto(out *ReleaseID) {
*out = *in
......
......@@ -54,7 +54,7 @@ spec:
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
description: 'Limits describes the maximum amount of compute
resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/'
resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
type: object
requests:
additionalProperties:
......@@ -66,7 +66,7 @@ spec:
description: 'Requests describes the minimum amount of compute
resources required. If Requests is omitted for a container,
it defaults to Limits if that is explicitly specified, otherwise
to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/'
to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
type: object
type: object
type: object
......@@ -86,7 +86,7 @@ spec:
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
description: 'Limits describes the maximum amount of compute
resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/'
resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
type: object
requests:
additionalProperties:
......@@ -98,7 +98,7 @@ spec:
description: 'Requests describes the minimum amount of compute
resources required. If Requests is omitted for a container,
it defaults to Limits if that is explicitly specified, otherwise
to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/'
to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
type: object
type: object
type: object
......@@ -118,7 +118,7 @@ spec:
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
description: 'Limits describes the maximum amount of compute
resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/'
resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
type: object
requests:
additionalProperties:
......@@ -130,7 +130,7 @@ spec:
description: 'Requests describes the minimum amount of compute
resources required. If Requests is omitted for a container,
it defaults to Limits if that is explicitly specified, otherwise
to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/'
to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
type: object
type: object
type: object
......@@ -150,7 +150,7 @@ spec:
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
description: 'Limits describes the maximum amount of compute
resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/'
resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
type: object
requests:
additionalProperties:
......@@ -162,7 +162,7 @@ spec:
description: 'Requests describes the minimum amount of compute
resources required. If Requests is omitted for a container,
it defaults to Limits if that is explicitly specified, otherwise
to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/'
to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
type: object
type: object
type: object
......@@ -182,7 +182,7 @@ spec:
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
description: 'Limits describes the maximum amount of compute
resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/'
resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
type: object
requests:
additionalProperties:
......@@ -194,7 +194,7 @@ spec:
description: 'Requests describes the minimum amount of compute
resources required. If Requests is omitted for a container,
it defaults to Limits if that is explicitly specified, otherwise
to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/'
to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
type: object
type: object
type: object
......@@ -214,7 +214,7 @@ spec:
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
description: 'Limits describes the maximum amount of compute
resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/'
resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
type: object
requests:
additionalProperties:
......@@ -226,7 +226,7 @@ spec:
description: 'Requests describes the minimum amount of compute
resources required. If Requests is omitted for a container,
it defaults to Limits if that is explicitly specified, otherwise
to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/'
to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
type: object
type: object
type: object
......
......@@ -74,9 +74,24 @@ spec:
and other supported configuration from the given git repo to
the site, by building an image specific to this site from the
generic CERN one. Add extra modules to your website with Composer
through a Git repo, following these docs
through a Git repo. This field is deprecated.
pattern: '[(http(s)?):\/\/(www\.)?a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)'
type: string
extraConfigurationRepository:
description: ExtraConfigurationRepository injects the composer
project and other supported configuration from the given git
repo to the site, by building an image specific to this site
from the generic CERN one.
properties:
branch:
default: master
description: Branch specifies the branch of the repository
type: string
repositoryUrl:
description: RepositoryUrl specifies the URL of the repository
pattern: '[(http(s)?):\/\/(www\.)?a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)'
type: string
type: object
qosClass:
default: standard
description: QoSClass specifies the website's performance and
......
......@@ -10,6 +10,9 @@ spec:
releaseSpec: "RELEASE-2021.11.19T01-52-19Z"
configuration:
extraConfigurationRepo: "https://gitlab.cern.ch/drupal/paas/example-drupalsite-d8-extraconfig.git"
extraConfigurationRepository:
branch: "master"
repositoryUrl: "https://gitlab.cern.ch/drupal/paas/example-drupalsite-d8-extraconfig.git"
qosClass: "standard"
databaseClass: "standard"
diskSize: "1Gi"
......@@ -287,7 +287,8 @@ func (r *DrupalSiteReconciler) Reconcile(ctx context.Context, req ctrl.Request)
// If it's a site with extraConfig Spec, add the gitlab webhook trigger to the Status
// The URL is dependent on BuildConfig name, which is based on nameVersionHash() function. Therefore it needs to be updated when there is a ReleaseID update
// For consistency, we update the field on every reconcile
if len(drupalSite.Spec.Configuration.ExtraConfigurationRepo) > 0 {
// TODO: Remove logic for ExtraConfigurationRepo once we deprecate the field
if len(drupalSite.Spec.Configuration.ExtraConfigurationRepo) > 0 || len(drupalSite.Spec.Configuration.ExtraConfigurationRepository.RepositoryUrl) > 0 {
update = addGitlabWebhookToStatus(ctx, drupalSite) || update
}
......
......@@ -204,9 +204,15 @@ func (r *DrupalSiteReconciler) ensureSpecFinalizer(ctx context.Context, drp *web
drp.Spec.Configuration.DiskSize = sourceSite.Spec.Configuration.DiskSize
}
// The extraConfigurationRepo should be set in the clone site if defined in the source
// TODO: Remove logic for ExtraConfigurationRepo once we deprecate the field
if sourceSite.Spec.Configuration.ExtraConfigurationRepo != "" && drp.Spec.Configuration.ExtraConfigurationRepo == "" {
drp.Spec.Configuration.ExtraConfigurationRepo = sourceSite.Spec.Configuration.ExtraConfigurationRepo
}
// The extraConfigurationRepository should be set in the clone site if defined in the source
if sourceSite.Spec.Configuration.ExtraConfigurationRepository.Branch != "" && sourceSite.Spec.Configuration.ExtraConfigurationRepository.RepositoryUrl != "" && drp.Spec.Configuration.ExtraConfigurationRepository.Branch == "" && drp.Spec.Configuration.ExtraConfigurationRepository.RepositoryUrl != "" {
drp.Spec.Configuration.ExtraConfigurationRepository.Branch = sourceSite.Spec.Configuration.ExtraConfigurationRepository.Branch
drp.Spec.Configuration.ExtraConfigurationRepository.RepositoryUrl = sourceSite.Spec.Configuration.ExtraConfigurationRepository.RepositoryUrl
}
}
// Initialize 'spec.version.releaseSpec' if empty
if len(drp.Spec.Version.ReleaseSpec) == 0 {
......
......@@ -75,8 +75,8 @@ func (r *DrupalSiteReconciler) ensureResources(drp *webservicesv1a1.DrupalSite,
ctx := context.TODO()
// 1. BuildConfigs and ImageStreams
if len(drp.Spec.Configuration.ExtraConfigurationRepo) > 0 {
// TODO: Remove logic for ExtraConfigurationRepo once we deprecate the field
if len(drp.Spec.Configuration.ExtraConfigurationRepo) > 0 || len(drp.Spec.Configuration.ExtraConfigurationRepository.RepositoryUrl) > 0 {
if transientErr := r.ensureResourceX(ctx, drp, "is_s2i", log); transientErr != nil {
transientErrs = append(transientErrs, transientErr.Wrap("%v: for S2I SiteBuilder ImageStream"))
}
......@@ -643,13 +643,6 @@ func buildConfigForDrupalSiteBuilderS2I(currentobject *buildv1.BuildConfig, d *w
CommonSpec: buildv1.CommonSpec{
Resources: BuildResources,
CompletionDeadlineSeconds: pointer.Int64Ptr(1200),
Source: buildv1.BuildSource{
Git: &buildv1.GitBuildSource{
// TODO: support branches https://gitlab.cern.ch/drupal/paas/drupalsite-operator/-/issues/28
Ref: "master",
URI: d.Spec.Configuration.ExtraConfigurationRepo,
},
},
Strategy: buildv1.BuildStrategy{
SourceStrategy: &buildv1.SourceBuildStrategy{
From: corev1.ObjectReference{
......@@ -678,6 +671,22 @@ func buildConfigForDrupalSiteBuilderS2I(currentobject *buildv1.BuildConfig, d *w
},
}
}
// TODO: Remove logic for ExtraConfigurationRepo once we deprecate the field
if currentobject.CreationTimestamp.IsZero() && len(d.Spec.Configuration.ExtraConfigurationRepo) > 0 {
currentobject.Spec.CommonSpec.Source = buildv1.BuildSource{
Git: &buildv1.GitBuildSource{
Ref: "master",
URI: d.Spec.Configuration.ExtraConfigurationRepo,
},
}
} else if currentobject.CreationTimestamp.IsZero() && len(d.Spec.Configuration.ExtraConfigurationRepository.RepositoryUrl) > 0 {
currentobject.Spec.CommonSpec.Source = buildv1.BuildSource{
Git: &buildv1.GitBuildSource{
Ref: d.Spec.Configuration.ExtraConfigurationRepository.Branch,
URI: string(d.Spec.Configuration.ExtraConfigurationRepository.RepositoryUrl),
},
}
}
if currentobject.Labels == nil {
currentobject.Labels = map[string]string{}
}
......@@ -1129,7 +1138,8 @@ func deploymentForDrupalSite(currentobject *appsv1.Deployment, databaseSecret st
}
// Ensure S2I rollouts on image change
if len(d.Spec.Configuration.ExtraConfigurationRepo) > 0 {
// TODO: Remove logic for ExtraConfigurationRepo once we deprecate the field
if len(d.Spec.Configuration.ExtraConfigurationRepo) > 0 || len(d.Spec.ExtraConfigurationRepository.RepositoryUrl) > 0 {
// This annotation is required to trigger new rollout, when the imagestream gets updated with a new image for the given tag. Without this, deployments might start running with
// a wrong image built from a different build, that is left out on the node
currentobject.Annotations["image.openshift.io/triggers"] =
......
......@@ -323,8 +323,9 @@ func releaseID(d *webservicesv1a1.DrupalSite) string {
// sitebuilderImageRefToUse returns which base image to use, depending on whether the field `ExtraConfigurationRepo` is set.
// If yes, the S2I buildconfig will be used; sitebuilderImageRefToUse returns the output of imageStreamForDrupalSiteBuilderS2I().
// Otherwise, returns the sitebuilder base
// TODO: Remove logic for ExtraConfigurationRepo once we deprecate the field
func sitebuilderImageRefToUse(d *webservicesv1a1.DrupalSite, releaseID string) corev1.ObjectReference {
if len(d.Spec.Configuration.ExtraConfigurationRepo) > 0 {
if len(d.Spec.Configuration.ExtraConfigurationRepo) > 0 || len(d.Spec.Configuration.ExtraConfigurationRepository.RepositoryUrl) > 0 {
return corev1.ObjectReference{
Kind: "ImageStreamTag",
Name: "image-registry.openshift-image-registry.svc:5000/" + d.Namespace + "/sitebuilder-s2i-" + d.Name + ":" + releaseID,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment