Skip to content
Snippets Groups Projects
Commit 146e083f authored by Michal Kolodziejski's avatar Michal Kolodziejski :bug:
Browse files

Merge branch '11_rename_StaticSite_CR_to_GitlabPagesSite' into 'development'

[#11] Rename StaticSite CR to GitlabPagesSite

See merge request paas-tools/operators/static-site-operator!7
parents 6085a9ae c1008fb5
No related branches found
No related tags found
2 merge requests!8GitlabPagesSite operator,!7[#11] Rename StaticSite CR to GitlabPagesSite
Pipeline #2818912 passed
......@@ -97,7 +97,7 @@ build: generate fmt vet ## Build manager binary.
go build -o bin/manager main.go
run: manifests generate fmt vet build ## Build and run a controller from your host.
go run ./main.go --virtual-hosts-configmap-name=staticsite-sample --namespace=test-gitlab-pages --gitlab-pages-url=http://gitlab-pages-webserver:8090/ --auth-proxy-service-name=static-site-authenticating-proxy-chart
go run ./main.go --virtual-hosts-secret-name=staticsite-sample --namespace=test-gitlab-pages --gitlab-pages-url=http://gitlab-pages-webserver:8090/ --auth-proxy-service-name=static-site-authenticating-proxy-chart
docker-build: test ## Build docker image with the manager.
docker build -t ${IMG} .
......
......@@ -4,15 +4,15 @@ layout:
plugins:
manifests.sdk.operatorframework.io/v2: {}
scorecard.sdk.operatorframework.io/v2: {}
projectName: static-site-operator
repo: gitlab.cern.ch/paas-tools/operators/static-site-operator
projectName: gitlab-pages-site-operator
repo: gitlab.cern.ch/paas-tools/operators/gitlab-pages-site-operator
resources:
- api:
crdVersion: v1
namespaced: true
controller: true
domain: webservices.cern.ch
kind: StaticSite
path: gitlab.cern.ch/paas-tools/operators/static-site-operator/api/v1alpha1
kind: GitlabPagesSite
path: gitlab.cern.ch/paas-tools/operators/gitlab-pages-site-operator/api/v1alpha1
version: v1alpha1
version: "3"
......@@ -23,8 +23,8 @@ import (
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
// StaticSiteSpec defines the desired state of StaticSite
type StaticSiteSpec struct {
// GitlabPagesSiteSpec defines the desired state of GitlabPagesSite
type GitlabPagesSiteSpec struct {
// Anonymous defines if the site needs authentication or not
// +kubebuilder:validation:Optional
// +kubebuilder:validation:Enum=true;false
......@@ -35,8 +35,8 @@ type StaticSiteSpec struct {
Host string `json:"host"`
}
// StaticSiteStatus defines the observed state of StaticSite
type StaticSiteStatus struct {
// GitlabPagesSiteStatus defines the observed state of GitlabPagesSite
type GitlabPagesSiteStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
}
......@@ -44,26 +44,26 @@ type StaticSiteStatus struct {
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
// StaticSite is the Schema for the staticsites API.
// The goal of the operator is to mantain sync the Route and the configuration of a Static Site.
// GitlabPagesSite is the Schema for the gitlabpagessites API.
// The goal of the operator is to mantain sync the Route and the configuration of a Gitlab Pages Site.
// The configuration is located on the ConfigMap
type StaticSite struct {
type GitlabPagesSite struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec StaticSiteSpec `json:"spec,omitempty"`
Status StaticSiteStatus `json:"status,omitempty"`
Spec GitlabPagesSiteSpec `json:"spec,omitempty"`
Status GitlabPagesSiteStatus `json:"status,omitempty"`
}
//+kubebuilder:object:root=true
// StaticSiteList contains a list of StaticSite
type StaticSiteList struct {
// GitlabPagesSiteList contains a list of GitlabPagesSite
type GitlabPagesSiteList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []StaticSite `json:"items"`
Items []GitlabPagesSite `json:"items"`
}
func init() {
SchemeBuilder.Register(&StaticSite{}, &StaticSiteList{})
SchemeBuilder.Register(&GitlabPagesSite{}, &GitlabPagesSiteList{})
}
......@@ -25,7 +25,7 @@ import (
)
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *StaticSite) DeepCopyInto(out *StaticSite) {
func (in *GitlabPagesSite) DeepCopyInto(out *GitlabPagesSite) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
......@@ -33,18 +33,18 @@ func (in *StaticSite) DeepCopyInto(out *StaticSite) {
out.Status = in.Status
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StaticSite.
func (in *StaticSite) DeepCopy() *StaticSite {
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GitlabPagesSite.
func (in *GitlabPagesSite) DeepCopy() *GitlabPagesSite {
if in == nil {
return nil
}
out := new(StaticSite)
out := new(GitlabPagesSite)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *StaticSite) DeepCopyObject() runtime.Object {
func (in *GitlabPagesSite) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
......@@ -52,31 +52,31 @@ func (in *StaticSite) DeepCopyObject() runtime.Object {
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *StaticSiteList) DeepCopyInto(out *StaticSiteList) {
func (in *GitlabPagesSiteList) DeepCopyInto(out *GitlabPagesSiteList) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ListMeta.DeepCopyInto(&out.ListMeta)
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]StaticSite, len(*in))
*out = make([]GitlabPagesSite, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StaticSiteList.
func (in *StaticSiteList) DeepCopy() *StaticSiteList {
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GitlabPagesSiteList.
func (in *GitlabPagesSiteList) DeepCopy() *GitlabPagesSiteList {
if in == nil {
return nil
}
out := new(StaticSiteList)
out := new(GitlabPagesSiteList)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *StaticSiteList) DeepCopyObject() runtime.Object {
func (in *GitlabPagesSiteList) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
......@@ -84,31 +84,31 @@ func (in *StaticSiteList) DeepCopyObject() runtime.Object {
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *StaticSiteSpec) DeepCopyInto(out *StaticSiteSpec) {
func (in *GitlabPagesSiteSpec) DeepCopyInto(out *GitlabPagesSiteSpec) {
*out = *in
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StaticSiteSpec.
func (in *StaticSiteSpec) DeepCopy() *StaticSiteSpec {
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GitlabPagesSiteSpec.
func (in *GitlabPagesSiteSpec) DeepCopy() *GitlabPagesSiteSpec {
if in == nil {
return nil
}
out := new(StaticSiteSpec)
out := new(GitlabPagesSiteSpec)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *StaticSiteStatus) DeepCopyInto(out *StaticSiteStatus) {
func (in *GitlabPagesSiteStatus) DeepCopyInto(out *GitlabPagesSiteStatus) {
*out = *in
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StaticSiteStatus.
func (in *StaticSiteStatus) DeepCopy() *StaticSiteStatus {
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GitlabPagesSiteStatus.
func (in *GitlabPagesSiteStatus) DeepCopy() *GitlabPagesSiteStatus {
if in == nil {
return nil
}
out := new(StaticSiteStatus)
out := new(GitlabPagesSiteStatus)
in.DeepCopyInto(out)
return out
}
......@@ -6,22 +6,22 @@ metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.4.1
creationTimestamp: null
name: staticsites.webservices.cern.ch
name: gitlabpagessites.webservices.cern.ch
spec:
group: webservices.cern.ch
names:
kind: StaticSite
listKind: StaticSiteList
plural: staticsites
singular: staticsite
kind: GitlabPagesSite
listKind: GitlabPagesSiteList
plural: gitlabpagessites
singular: gitlabpagessite
scope: Namespaced
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
description: StaticSite is the Schema for the staticsites API. The goal of
the operator is to mantain sync the Route and the configuration of a Static
Site. The configuration is located on the ConfigMap
description: GitlabPagesSite is the Schema for the gitlabpagessites API. The
goal of the operator is to mantain sync the Route and the configuration
of a Gitlab Pages Site. The configuration is located on the ConfigMap
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
......@@ -36,7 +36,7 @@ spec:
metadata:
type: object
spec:
description: StaticSiteSpec defines the desired state of StaticSite
description: GitlabPagesSiteSpec defines the desired state of GitlabPagesSite
properties:
anonymous:
default: false
......@@ -53,7 +53,7 @@ spec:
- host
type: object
status:
description: StaticSiteStatus defines the observed state of StaticSite
description: GitlabPagesSiteStatus defines the observed state of GitlabPagesSite
type: object
type: object
served: true
......
......@@ -57,7 +57,7 @@ rules:
- apiGroups:
- webservices.cern.ch
resources:
- staticsites
- gitlabpagessites
verbs:
- create
- delete
......@@ -69,13 +69,13 @@ rules:
- apiGroups:
- webservices.cern.ch
resources:
- staticsites/finalizers
- gitlabpagessites/finalizers
verbs:
- update
- apiGroups:
- webservices.cern.ch
resources:
- staticsites/status
- gitlabpagessites/status
verbs:
- get
- patch
......
......@@ -39,12 +39,12 @@ func init() {
templ = template.Must(template.New("httpd-config.template").Parse(httpdConfigTemplate))
}
func generateSecretKey(staticSite *webservicescernchv1alpha1.StaticSite) string {
return fmt.Sprintf("%s-static-site.conf", staticSite.ObjectMeta.Name)
func generateSecretKey(gitlabPagesSite *webservicescernchv1alpha1.GitlabPagesSite) string {
return fmt.Sprintf("%s-static-site.conf", gitlabPagesSite.ObjectMeta.Name)
}
type templateData struct {
webservicescernchv1alpha1.StaticSiteSpec
webservicescernchv1alpha1.GitlabPagesSiteSpec
GitlabPagesURL string
CryptoPassPhrase string
......@@ -53,13 +53,13 @@ type templateData struct {
}
}
func generateHttpdVhostConfiguration(staticSite *webservicescernchv1alpha1.StaticSite, oidcSecret *v1.Secret, gitlabPagesURL string, cryptoPassPhrase string) ([]byte, error) {
func generateHttpdVhostConfiguration(gitlabPagesSite *webservicescernchv1alpha1.GitlabPagesSite, oidcSecret *v1.Secret, gitlabPagesURL string, cryptoPassPhrase string) ([]byte, error) {
var buf bytes.Buffer
data := templateData{
StaticSiteSpec: staticSite.Spec,
GitlabPagesURL: gitlabPagesURL,
CryptoPassPhrase: cryptoPassPhrase,
GitlabPagesSiteSpec: gitlabPagesSite.Spec,
GitlabPagesURL: gitlabPagesURL,
CryptoPassPhrase: cryptoPassPhrase,
}
data.OIDCSecret.ClientID = string(oidcSecret.Data["clientID"])
......
......@@ -15,7 +15,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)
func (r *StaticSiteReconciler) ensureHttpdSecret(staticSite *webservicescernchv1alpha1.StaticSite) (*corev1.Secret, error) {
func (r *GitlabPagesSiteReconciler) ensureHttpdSecret(gitlabPagesSite *webservicescernchv1alpha1.GitlabPagesSite) (*corev1.Secret, error) {
secret := &corev1.Secret{}
err := r.Get(
context.TODO(),
......@@ -30,9 +30,9 @@ func (r *StaticSiteReconciler) ensureHttpdSecret(staticSite *webservicescernchv1
return secret, nil
}
func (r *StaticSiteReconciler) getApplicationRegistration(ctx context.Context, staticSite *webservicescernchv1alpha1.StaticSite) (*authzalpha1.ApplicationRegistration, error) {
func (r *GitlabPagesSiteReconciler) getApplicationRegistration(ctx context.Context, gitlabPagesSite *webservicescernchv1alpha1.GitlabPagesSite) (*authzalpha1.ApplicationRegistration, error) {
appReg := &authzalpha1.ApplicationRegistration{}
appRegistrationName := types.NamespacedName{Namespace: staticSite.Namespace, Name: staticSite.Name}
appRegistrationName := types.NamespacedName{Namespace: gitlabPagesSite.Namespace, Name: gitlabPagesSite.Name}
if err := r.Get(ctx, appRegistrationName, appReg); err != nil {
if kerrors.IsNotFound(err) {
......@@ -45,17 +45,17 @@ func (r *StaticSiteReconciler) getApplicationRegistration(ctx context.Context, s
return appReg, nil
}
func (r *StaticSiteReconciler) ensureStaticSiteHttpdConfig(staticSite *webservicescernchv1alpha1.StaticSite, secret *corev1.Secret, oidcSecret *corev1.Secret) error {
func (r *GitlabPagesSiteReconciler) ensureGitlabPagesSiteHttpdConfig(gitlabPagesSite *webservicescernchv1alpha1.GitlabPagesSite, secret *corev1.Secret, oidcSecret *corev1.Secret) error {
if secret.Data == nil {
secret.Data = map[string][]byte{}
}
httpdConfig, err := generateHttpdVhostConfiguration(staticSite, oidcSecret, r.GitlabPagesURL, r.CryptoPassPhrase)
httpdConfig, err := generateHttpdVhostConfiguration(gitlabPagesSite, oidcSecret, r.GitlabPagesURL, r.CryptoPassPhrase)
if err != nil {
return err
}
secret.Data[generateSecretKey(staticSite)] = httpdConfig
secret.Data[generateSecretKey(gitlabPagesSite)] = httpdConfig
err = r.Update(context.TODO(), secret, &client.UpdateOptions{})
if err != nil {
......@@ -65,13 +65,13 @@ func (r *StaticSiteReconciler) ensureStaticSiteHttpdConfig(staticSite *webservic
return nil
}
// ensureRoute ensures the existence of a Route for a given StaticSite
func (r *StaticSiteReconciler) ensureRoute(staticSite *webservicescernchv1alpha1.StaticSite) error {
_, err := r.getRoute(staticSite)
// ensureRoute ensures the existence of a Route for a given GitlabPagesSite
func (r *GitlabPagesSiteReconciler) ensureRoute(gitlabPagesSite *webservicescernchv1alpha1.GitlabPagesSite) error {
_, err := r.getRoute(gitlabPagesSite)
if err != nil {
if kerrors.IsNotFound(err) {
route, err := r.newRouteForStaticSite(staticSite)
route, err := r.newRouteForGitlabPagesSite(gitlabPagesSite)
if err != nil {
return err
}
......@@ -85,7 +85,7 @@ func (r *StaticSiteReconciler) ensureRoute(staticSite *webservicescernchv1alpha1
return nil
}
func (r *StaticSiteReconciler) newRouteForStaticSite(staticSite *webservicescernchv1alpha1.StaticSite) (*routev1.Route, error) {
func (r *GitlabPagesSiteReconciler) newRouteForGitlabPagesSite(gitlabPagesSite *webservicescernchv1alpha1.GitlabPagesSite) (*routev1.Route, error) {
authenticatingProxyService := &corev1.Service{}
err := r.Get(context.TODO(), types.NamespacedName{Namespace: r.Namespace, Name: r.AuthProxyServiceName}, authenticatingProxyService)
......@@ -95,7 +95,7 @@ func (r *StaticSiteReconciler) newRouteForStaticSite(staticSite *webservicescern
route := &routev1.Route{
ObjectMeta: metav1.ObjectMeta{
Name: staticSite.Name,
Name: gitlabPagesSite.Name,
Namespace: r.Namespace,
},
Spec: routev1.RouteSpec{
......@@ -107,27 +107,27 @@ func (r *StaticSiteReconciler) newRouteForStaticSite(staticSite *webservicescern
Kind: "Service",
Name: authenticatingProxyService.ObjectMeta.Name,
},
Host: staticSite.Spec.Host,
Host: gitlabPagesSite.Spec.Host,
Port: &routev1.RoutePort{
TargetPort: intstr.FromInt(int(authenticatingProxyService.Spec.Ports[0].Port)),
},
},
}
// Set StaticSite instance as the owner and controller. This will set
// Set GitlabPagesSite instance as the owner and controller. This will set
// the OwnerReferences to the route, and will trigger a deletion of the
// route when the StaticSite parent gets deleted.
// if err := controllerutil.SetControllerReference(staticSite, route, r.Scheme); err != nil {
// route when the GitlabPagesSite parent gets deleted.
// if err := controllerutil.SetControllerReference(gitlabPagesSite, route, r.Scheme); err != nil {
// return nil, fmt.Errorf("failed to set controller reference for route creation with err: %v", err)
// }
return route, nil
}
func (r *StaticSiteReconciler) getRoute(staticSite *webservicescernchv1alpha1.StaticSite) (route *routev1.Route, err error) {
func (r *GitlabPagesSiteReconciler) getRoute(gitlabPagesSite *webservicescernchv1alpha1.GitlabPagesSite) (route *routev1.Route, err error) {
route = &routev1.Route{}
key := types.NamespacedName{
Name: staticSite.Name,
Name: gitlabPagesSite.Name,
Namespace: r.Namespace,
}
......@@ -142,7 +142,7 @@ func (r *StaticSiteReconciler) getRoute(staticSite *webservicescernchv1alpha1.St
}
// createRoute creates a route for the given site
func (r *StaticSiteReconciler) createRoute(route *routev1.Route) error {
func (r *GitlabPagesSiteReconciler) createRoute(route *routev1.Route) error {
if err := r.Create(context.TODO(), route); err != nil {
return fmt.Errorf("failed to create route: %v", err)
}
......
......@@ -38,10 +38,10 @@ import (
webservicescernchv1alpha1 "gitlab.cern.ch/paas-tools/operators/static-site-operator/api/v1alpha1"
)
const staticSiteFinalizer string = "webservices.cern.ch/static-site-finalizer"
const gitlabPagesSiteFinalizer string = "webservices.cern.ch/static-site-finalizer"
// StaticSiteReconciler reconciles a StaticSite object
type StaticSiteReconciler struct {
// GitlabPagesSiteReconciler reconciles a GitlabPagesSite object
type GitlabPagesSiteReconciler struct {
client.Client
Scheme *runtime.Scheme
Namespace string
......@@ -52,9 +52,9 @@ type StaticSiteReconciler struct {
logger logr.Logger
}
//+kubebuilder:rbac:groups=webservices.cern.ch,resources=staticsites,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups=webservices.cern.ch,resources=staticsites/status,verbs=get;update;patch
//+kubebuilder:rbac:groups=webservices.cern.ch,resources=staticsites/finalizers,verbs=update
//+kubebuilder:rbac:groups=webservices.cern.ch,resources=gitlabpagessites,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups=webservices.cern.ch,resources=gitlabpagessites/status,verbs=get;update;patch
//+kubebuilder:rbac:groups=webservices.cern.ch,resources=gitlabpagessites/finalizers,verbs=update
//+kubebuilder:rbac:groups=webservices.cern.ch,resources=applicationregistrations,verbs=get;list;watch
//+kubebuilder:rbac:groups=route.openshift.io,resources=routes,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups=route.openshift.io,resources=routes/custom-host,verbs=create;get;update;patch
......@@ -64,58 +64,58 @@ type StaticSiteReconciler struct {
// Reconcile is part of the main kubernetes reconciliation loop which aims to
// move the current state of the cluster closer to the desired state.
// TODO(user): Modify the Reconcile function to compare the state specified by
// the StaticSite object against the actual cluster state, and then
// the GitlabPagesSite object against the actual cluster state, and then
// perform operations to make the cluster state reflect the state specified by
// the user.
//
// For more details, check Reconcile and its Result here:
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.8.3/pkg/reconcile
func (r *StaticSiteReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
r.logger = log.Log.WithValues("StaticSite", req.NamespacedName)
r.logger.Info("Reconciling StaticSite")
func (r *GitlabPagesSiteReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
r.logger = log.Log.WithValues("GitlabPagesSite", req.NamespacedName)
r.logger.Info("Reconciling GitlabPagesSite")
staticSite := &webservicescernchv1alpha1.StaticSite{}
if err := r.Get(context.TODO(), req.NamespacedName, staticSite); err != nil {
gitlabPagesSite := &webservicescernchv1alpha1.GitlabPagesSite{}
if err := r.Get(context.TODO(), req.NamespacedName, gitlabPagesSite); err != nil {
if errors.IsNotFound(err) {
r.logger.Info("StaticSite resource not found. Ignoring since object must have been deleted.")
r.logger.Info("GitlabPagesSite resource not found. Ignoring since object must have been deleted.")
return ctrl.Result{}, nil
}
r.logger.Error(err, "Failed to get StaticSite")
r.logger.Error(err, "Failed to get GitlabPagesSite")
return ctrl.Result{}, err
}
secret, err := r.ensureHttpdSecret(staticSite)
secret, err := r.ensureHttpdSecret(gitlabPagesSite)
if err != nil {
// TODO: should we requeue in hope that the Secret will be created in the meantime?
return ctrl.Result{}, err
}
// StaticSite has been deleted - we should handle the deletion of the entry from the Secret
if staticSite.GetDeletionTimestamp() != nil {
r.logger.Info("Deleting StaticSite")
// GitlabPagesSite has been deleted - we should handle the deletion of the entry from the Secret
if gitlabPagesSite.GetDeletionTimestamp() != nil {
r.logger.Info("Deleting GitlabPagesSite")
if controllerutil.ContainsFinalizer(staticSite, staticSiteFinalizer) {
if controllerutil.ContainsFinalizer(gitlabPagesSite, gitlabPagesSiteFinalizer) {
// TODO: Remove the entry from the Secret
delete(secret.Data, generateSecretKey(staticSite))
delete(secret.Data, generateSecretKey(gitlabPagesSite))
err := r.Update(context.TODO(), secret, &client.UpdateOptions{})
if err != nil {
return ctrl.Result{}, err
}
controllerutil.RemoveFinalizer(staticSite, staticSiteFinalizer)
err = r.Update(context.TODO(), staticSite, &client.UpdateOptions{})
controllerutil.RemoveFinalizer(gitlabPagesSite, gitlabPagesSiteFinalizer)
err = r.Update(context.TODO(), gitlabPagesSite, &client.UpdateOptions{})
if err != nil {
return ctrl.Result{}, err
}
}
r.logger.Info("StaticSite has been deleted")
r.logger.Info("GitlabPagesSite has been deleted")
return ctrl.Result{}, nil
}
appReg, err := r.getApplicationRegistration(ctx, staticSite)
appReg, err := r.getApplicationRegistration(ctx, gitlabPagesSite)
if err != nil {
return ctrl.Result{}, err
}
......@@ -129,7 +129,7 @@ func (r *StaticSiteReconciler) Reconcile(ctx context.Context, req ctrl.Request)
oidcSecret := &v1.Secret{}
namespaceName := types.NamespacedName{
Namespace: staticSite.Namespace,
Namespace: gitlabPagesSite.Namespace,
Name: appReg.Status.ClientCredentialsSecret,
}
......@@ -138,22 +138,22 @@ func (r *StaticSiteReconciler) Reconcile(ctx context.Context, req ctrl.Request)
return ctrl.Result{}, err
}
err = r.ensureStaticSiteHttpdConfig(staticSite, secret, oidcSecret)
err = r.ensureGitlabPagesSiteHttpdConfig(gitlabPagesSite, secret, oidcSecret)
if err != nil {
r.logger.Error(err, "There was a problem while generating httpd config for the StaticSite")
r.logger.Error(err, "There was a problem while generating httpd config for the GitlabPagesSite")
return ctrl.Result{}, err
}
err = r.ensureRoute(staticSite)
err = r.ensureRoute(gitlabPagesSite)
if err != nil {
r.logger.Error(err, "There was a problem while creating a Route")
return ctrl.Result{}, err
}
if !controllerutil.ContainsFinalizer(staticSite, staticSiteFinalizer) {
controllerutil.AddFinalizer(staticSite, staticSiteFinalizer)
if !controllerutil.ContainsFinalizer(gitlabPagesSite, gitlabPagesSiteFinalizer) {
controllerutil.AddFinalizer(gitlabPagesSite, gitlabPagesSiteFinalizer)
err = r.Update(context.TODO(), staticSite, &client.UpdateOptions{})
err = r.Update(context.TODO(), gitlabPagesSite, &client.UpdateOptions{})
if err != nil {
return ctrl.Result{}, err
}
......@@ -163,10 +163,10 @@ func (r *StaticSiteReconciler) Reconcile(ctx context.Context, req ctrl.Request)
}
// SetupWithManager sets up the controller with the Manager.
func (r *StaticSiteReconciler) SetupWithManager(mgr ctrl.Manager) error {
func (r *GitlabPagesSiteReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&webservicescernchv1alpha1.StaticSite{}).
// TODO: We can't set the controller reference for now since the `Route` and `StaticSite` live in different namespaces
For(&webservicescernchv1alpha1.GitlabPagesSite{}).
// TODO: We can't set the controller reference for now since the `Route` and `GitlabPagesSite` live in different namespaces
Owns(&routev1.Route{}).
Complete(r)
}
......@@ -126,7 +126,7 @@ func main() {
os.Exit(1)
}
if err = (&controllers.StaticSiteReconciler{
if err = (&controllers.GitlabPagesSiteReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
VirtualHostsSecretName: virtualHostsSecretName,
......@@ -135,7 +135,7 @@ func main() {
AuthProxyServiceName: authProxyServiceName,
CryptoPassPhrase: cryptoPassPhrase,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "StaticSite")
setupLog.Error(err, "unable to create controller", "controller", "GitlabPagesSite")
os.Exit(1)
}
//+kubebuilder:scaffold:builder
......
......@@ -3,19 +3,30 @@ kind: ApplicationRegistration
metadata:
name: staticsite-sample
spec:
applicationName: "kolodzie-test-hugo" # unique
# must be unique
applicationName: "kolodzie-test-hugo"
description: "This is a sample"
homePage: "kolodzie-test-hugo.webtest.cern.ch" # optional
# optional
homePage: "kolodzie-test-hugo.webtest.cern.ch"
initialOwner:
username: "kolodzie" # policy out of scope
username: "kolodzie"
initialResourceCategory: "Official"
---
apiVersion: webservices.cern.ch/v1alpha1
kind: StaticSite
kind: OidcReturnURI
metadata:
name: staticsite-sample
spec:
anonymous: true
host: kolodzie-test-hugo.webtest.cern.ch
\ No newline at end of file
redirectURI: "https://kolodzie-test-hugo.webtest.cern.ch/redirect-uri"
---
apiVersion: webservices.cern.ch/v1alpha1
kind: GitlabPagesSite
metadata:
name: staticsite-sample
spec:
anonymous: false
host: kolodzie-test-hugo.webtest.cern.ch
......@@ -3,17 +3,28 @@ kind: ApplicationRegistration
metadata:
name: staticsite-sample-2
spec:
applicationName: "kolodzie-test-hexo" # unique
# must be unique
applicationName: "kolodzie-test-hexo"
description: "This is a sample"
homePage: "kolodzie-test-hexo.webtest.cern.ch" # optional
# optional
homePage: "kolodzie-test-hexo.webtest.cern.ch"
initialOwner:
username: "kolodzie" # policy out of scope
username: "kolodzie"
initialResourceCategory: "Official"
---
apiVersion: webservices.cern.ch/v1alpha1
kind: StaticSite
kind: OidcReturnURI
metadata:
name: staticsite-sample-2
spec:
redirectURI: "https://kolodzie-test-hexo.webtest.cern.ch/redirect-uri"
---
apiVersion: webservices.cern.ch/v1alpha1
kind: GitlabPagesSite
metadata:
name: staticsite-sample-2
spec:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment