diff --git a/Makefile b/Makefile index f9b67ab5ec6df23f2ac01e15030e35d8ffc0cf8b..440799195b2ba10e99267ae918457e4f5c320019 100644 --- a/Makefile +++ b/Makefile @@ -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} . diff --git a/PROJECT b/PROJECT index 4a8b6db696619df8b7fe8548a6c43bdf40de1f36..f14ad91950cf4bcd715f3a2549c1bf61c06c242c 100644 --- a/PROJECT +++ b/PROJECT @@ -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" diff --git a/api/v1alpha1/staticsite_types.go b/api/v1alpha1/staticsite_types.go index d6895051b666585ece2c0b9f6a3d88e2697b383f..a98c09a05ae224e1ff99d9cce0afd6802fd9a590 100644 --- a/api/v1alpha1/staticsite_types.go +++ b/api/v1alpha1/staticsite_types.go @@ -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{}) } diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index b1e1a67415405bc90929600632bc880882322821..d3338bf1e130bcc4f2749a961a058f3cbaccdf05 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -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 } diff --git a/chart/crds/webservices.cern.ch_staticsites.yaml b/chart/crds/webservices.cern.ch_gitlabpagessites.yaml similarity index 75% rename from chart/crds/webservices.cern.ch_staticsites.yaml rename to chart/crds/webservices.cern.ch_gitlabpagessites.yaml index 30c94b00e1f6fe063f41fad482bdeec0dbfe9897..c922eec788419f4558fc7c34a87afaa8dd52262c 100644 --- a/chart/crds/webservices.cern.ch_staticsites.yaml +++ b/chart/crds/webservices.cern.ch_gitlabpagessites.yaml @@ -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 diff --git a/chart/templates/role.yaml b/chart/templates/role.yaml index b6f53e57419a3de7a68e80c2e8096d71fdf3a8d1..d12a80a30764991d604fd926957575658dd55353 100644 --- a/chart/templates/role.yaml +++ b/chart/templates/role.yaml @@ -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 diff --git a/controllers/httpd_config.go b/controllers/httpd_config.go index 8c0dc91b313dd8c71dc9a1061532a3879cdeefa8..417154ff0dc29e1818eb10cb32594cecf2243ac1 100644 --- a/controllers/httpd_config.go +++ b/controllers/httpd_config.go @@ -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"]) diff --git a/controllers/operator_methods.go b/controllers/operator_methods.go index 35a9cc824d11134d04300a7170d05a387fcdba08..80a9ff8ecb174c7ef953786f85e0418bab050842 100644 --- a/controllers/operator_methods.go +++ b/controllers/operator_methods.go @@ -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) } diff --git a/controllers/staticsite_controller.go b/controllers/staticsite_controller.go index 38c5f5988ddcea543f1668185cc9f690e0781414..9114e12a0ecc17b03d50b19cc1a5260424f1226a 100644 --- a/controllers/staticsite_controller.go +++ b/controllers/staticsite_controller.go @@ -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) } diff --git a/main.go b/main.go index 45cc741675f145d49750e43332e1977cc2cc62e0..2839ea50fc71e9a64822ec2c7fe47e976bc25e89 100644 --- a/main.go +++ b/main.go @@ -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 diff --git a/samples/_v1alpha1_staticsite.yaml b/samples/_v1alpha1_staticsite.yaml index 70ed40cf7f57c63d9f3720b6a600020093c3a2de..9a76d9f5329e566bf7f2c5f2b69d5ac976e30850 100644 --- a/samples/_v1alpha1_staticsite.yaml +++ b/samples/_v1alpha1_staticsite.yaml @@ -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 diff --git a/samples/_v1alpha1_staticsite_2.yaml b/samples/_v1alpha1_staticsite_2.yaml index c22bfc9cd1a5fdf7ea74178e3cc2b9fe9b84616a..d5055d52e531ca2d1d6398e6a5d165537885be86 100644 --- a/samples/_v1alpha1_staticsite_2.yaml +++ b/samples/_v1alpha1_staticsite_2.yaml @@ -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: