Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
gitlab-pages-site-operator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
paas-tools
operators
gitlab-pages-site-operator
Commits
b40b66f0
Commit
b40b66f0
authored
3 years ago
by
Michal Kolodziejski
Browse files
Options
Downloads
Patches
Plain Diff
Reconcile GitlabPagesSite if its Route changes
parent
146e083f
No related branches found
No related tags found
No related merge requests found
Pipeline
#2819049
passed
3 years ago
Stage: build
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
controllers/operator_methods.go
+3
-7
3 additions, 7 deletions
controllers/operator_methods.go
controllers/staticsite_controller.go
+32
-2
32 additions, 2 deletions
controllers/staticsite_controller.go
with
35 additions
and
9 deletions
controllers/operator_methods.go
+
3
−
7
View file @
b40b66f0
...
...
@@ -97,6 +97,9 @@ func (r *GitlabPagesSiteReconciler) newRouteForGitlabPagesSite(gitlabPagesSite *
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
gitlabPagesSite
.
Name
,
Namespace
:
r
.
Namespace
,
Annotations
:
map
[
string
]
string
{
"webservices.cern.ch/static-site-owner"
:
types
.
NamespacedName
{
Name
:
gitlabPagesSite
.
Name
,
Namespace
:
gitlabPagesSite
.
Namespace
}
.
String
(),
},
},
Spec
:
routev1
.
RouteSpec
{
TLS
:
&
routev1
.
TLSConfig
{
...
...
@@ -114,13 +117,6 @@ func (r *GitlabPagesSiteReconciler) newRouteForGitlabPagesSite(gitlabPagesSite *
},
}
// 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 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
}
...
...
This diff is collapsed.
Click to expand it.
controllers/staticsite_controller.go
+
32
−
2
View file @
b40b66f0
...
...
@@ -20,6 +20,7 @@ import (
"context"
"fmt"
"reflect"
"strings"
"time"
"github.com/go-logr/logr"
...
...
@@ -32,7 +33,10 @@ import (
ctrl
"sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"
authzalpha1
"gitlab.cern.ch/paas-tools/operators/authz-operator/api/v1alpha1"
webservicescernchv1alpha1
"gitlab.cern.ch/paas-tools/operators/static-site-operator/api/v1alpha1"
...
...
@@ -109,6 +113,16 @@ func (r *GitlabPagesSiteReconciler) Reconcile(ctx context.Context, req ctrl.Requ
if
err
!=
nil
{
return
ctrl
.
Result
{},
err
}
route
,
err
:=
r
.
getRoute
(
gitlabPagesSite
)
if
err
!=
nil
{
return
ctrl
.
Result
{},
err
}
err
=
r
.
Delete
(
context
.
TODO
(),
route
,
&
client
.
DeleteOptions
{})
if
err
!=
nil
{
return
ctrl
.
Result
{},
err
}
}
r
.
logger
.
Info
(
"GitlabPagesSite has been deleted"
)
...
...
@@ -166,7 +180,23 @@ func (r *GitlabPagesSiteReconciler) Reconcile(ctx context.Context, req ctrl.Requ
func
(
r
*
GitlabPagesSiteReconciler
)
SetupWithManager
(
mgr
ctrl
.
Manager
)
error
{
return
ctrl
.
NewControllerManagedBy
(
mgr
)
.
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
{})
.
Watches
(
&
source
.
Kind
{
Type
:
&
routev1
.
Route
{}},
handler
.
EnqueueRequestsFromMapFunc
(
func
(
a
client
.
Object
)
[]
reconcile
.
Request
{
namespace
:=
a
.
GetNamespace
()
// we only care about the `Route`s within the namespace specified by r.Namespace
if
namespace
!=
r
.
Namespace
{
return
[]
reconcile
.
Request
{}
}
annotations
:=
a
.
GetAnnotations
()
if
annotations
!=
nil
&&
annotations
[
"webservices.cern.ch/static-site-owner"
]
!=
""
{
parts
:=
strings
.
Split
(
annotations
[
"webservices.cern.ch/static-site-owner"
],
"/"
)
return
[]
reconcile
.
Request
{{
NamespacedName
:
types
.
NamespacedName
{
Name
:
parts
[
1
],
Namespace
:
parts
[
0
]}}}
}
return
[]
reconcile
.
Request
{}
}),
)
.
Complete
(
r
)
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment