Skip to content

Commit d01e3ef

Browse files
committed
making namespace configurable for the operator
Signed-off-by: Mihai Sarbulescu <[email protected]>
1 parent b6a3304 commit d01e3ef

File tree

11 files changed

+64
-13
lines changed

11 files changed

+64
-13
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ It runs on the default Mongodb port (27017) and authentication is not required t
136136
With your local Porter configuration file pointed to the in-cluster mongodb server, you can use Porter to query and interact with installations created by the operator.
137137

138138
Expose the in-cluster mongodb server on the default mongo porter: 27017.
139+
* NOTE: Use your custom namespace if you have installed with the non-default one (porter-operator-system)
139140
```
140141
kubectl port-forward --namespace porter-operator-system svc/mongodb 27017:27017 >/dev/null &
141142
```

config/crd/bases/getporter.org_agentactions.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,8 @@ spec:
803803
defined in spec.resourceClaims, that are used
804804
by this container. \n This is an alpha field
805805
and requires enabling the DynamicResourceAllocation
806-
feature gate. \n This field is immutable."
806+
feature gate. \n This field is immutable.
807+
It can only be set for containers."
807808
items:
808809
description: ResourceClaim references one
809810
entry in PodSpec.ResourceClaims.

config/crd/bases/getporter.org_agentconfigs.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,7 @@ spec:
101101
storageClassName:
102102
description: StorageClassName is the name of the storage class that
103103
Porter will request when running the Porter Agent. It is used to
104-
determine what the storage class will be for the volume requested.
105-
The storage class must support ReadWriteOnce and ReadOnlyMany access modes
106-
as well as allow for 'chmod' to be executed.
104+
determine what the storage class will be for the volume requested
107105
type: string
108106
volumeSize:
109107
description: VolumeSize is the size of the persistent volume that

controllers/agentaction_controller.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,8 @@ func (r *AgentActionReconciler) createAgentJob(ctx context.Context, log logr.Log
483483
func (r *AgentActionReconciler) resolveAgentConfig(ctx context.Context, log logr.Logger, action *porterv1.AgentAction) (porterv1.AgentConfigSpecAdapter, error) {
484484
log.V(Log5Trace).Info("Resolving porter agent configuration")
485485

486+
operatorNamespace := operatorNamespaceDefault
487+
486488
logConfig := func(level string, config *porterv1.AgentConfig) {
487489
if config == nil || config.Name == "" {
488490
return
@@ -493,6 +495,8 @@ func (r *AgentActionReconciler) resolveAgentConfig(ctx context.Context, log logr
493495
"namespace", config.Namespace,
494496
"name", config.Name,
495497
"plugin", config.Spec.PluginConfigFile)
498+
499+
operatorNamespace = config.Namespace
496500
}
497501

498502
// Read agent configuration defined at the system level
@@ -550,6 +554,8 @@ func (r *AgentActionReconciler) resolveAgentConfig(ctx context.Context, log logr
550554
func (r *AgentActionReconciler) resolvePorterConfig(ctx context.Context, log logr.Logger, action *porterv1.AgentAction) (porterv1.PorterConfigSpec, error) {
551555
log.V(Log5Trace).Info("Resolving porter configuration file")
552556

557+
operatorNamespace := operatorNamespaceDefault
558+
553559
logConfig := func(level string, config *porterv1.PorterConfig) {
554560
if config == nil || config.Name == "" {
555561
return
@@ -558,6 +564,8 @@ func (r *AgentActionReconciler) resolvePorterConfig(ctx context.Context, log log
558564
"level", level,
559565
"namespace", config.Namespace,
560566
"name", config.Name)
567+
568+
operatorNamespace = config.Namespace
561569
}
562570

563571
// Provide a safe default config in case nothing is defined anywhere
@@ -568,7 +576,7 @@ func (r *AgentActionReconciler) resolvePorterConfig(ctx context.Context, log log
568576
{PluginConfig: porterv1.PluginConfig{
569577
Name: "in-cluster-mongodb",
570578
PluginSubKey: "mongodb",
571-
Config: runtime.RawExtension{Raw: []byte(`{"url":"mongodb://mongodb.porter-operator-system.svc.cluster.local"}`)},
579+
Config: runtime.RawExtension{Raw: []byte(`{"url":"mongodb://mongodb.` + operatorNamespace + `.svc.cluster.local"}`)},
572580
}},
573581
},
574582
}

controllers/agentaction_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@ func TestAgentActionReconciler_NoPluginsSpecified(t *testing.T) {
928928

929929
func TestAgentActionReconciler_resolveAgentConfig(t *testing.T) {
930930
systemCfg := porterv1.AgentConfig{
931-
ObjectMeta: metav1.ObjectMeta{Name: "default", Namespace: operatorNamespace},
931+
ObjectMeta: metav1.ObjectMeta{Name: "default", Namespace: operatorNamespaceDefault},
932932
Status: porterv1.AgentConfigStatus{
933933
Ready: true,
934934
},

controllers/installation_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
)
1919

2020
const (
21-
operatorNamespace = "porter-operator-system"
21+
operatorNamespaceDefault = "porter-operator-system"
2222
)
2323

2424
// InstallationReconciler calls porter to execute changes made to an Installation CRD

docs/content/install.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ porter credentials generate porterops -r ghcr.io/getporter/porter-operator:v0.8.
9595
```
9696

9797
Install the operator into the porter-operator-system namespace:
98+
* NOTE: Use your custom namespace if you want to install to a different one by adding **--param operatorNamespace=your-namespace-name**
9899
```
99100
porter install porterops -c porterops -r ghcr.io/getporter/porter-operator:v0.8.0
100101
```

docs/content/quickstart/_index.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ The bundle includes a custom action that prepares a namespace for you:
4040
porter invoke porterops --action configureNamespace --param namespace=quickstart -c porterops
4141
```
4242

43-
The Porter Operator is now installed on your cluster in the porter-operator-system namespace, along with a Mongodb server.
43+
The Porter Operator is now installed on your cluster in the porter-operator-system (or your custom namespace) namespace, along with a Mongodb server.
4444
This database is not secured with a username/password, so do not use this default installation configuration with production secrets!
4545
The cluster has a namespace, quickstart, where we will create resources and Porter will create jobs to run Porter.
4646

@@ -50,6 +50,7 @@ Let's update your local porter CLI to read the data from the operator's datastor
5050
This isn't necessary for the operator to work, but will allow us to see what's happening and understand how the operator works.
5151

5252
Run the following command to expose the operator's mongodb server to your localhost:
53+
* NOTE: Use your custom namespace if you have installed with the non-default one (porter-operator-system)
5354
```
5455
kubectl port-forward --namespace porter-operator-system svc/mongodb 27020:27017 >/dev/null &
5556
```

installer/helpers.sh

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4+
OPNAMESPACE="porter-operator-system"
5+
6+
setCustomNamespaceForOperator() {
7+
if [ -z "$1" ]; then
8+
echo "No namespace specified, using default $OPNAMESPACE"
9+
else
10+
OPNAMESPACE=$1
11+
echo "Using custom namespace $OPNAMESPACE"
12+
fi
13+
14+
# Replace the namespace in the operator.yaml
15+
echo "Setting namespace to $OPNAMESPACE"
16+
cd manifests
17+
kustomize edit set namespace $OPNAMESPACE
18+
kustomize build -o operator.yaml
19+
}
20+
421
setControllerImage() {
522
# Replace the manager image with the image packaged with the bundle
623
echo "Setting manager image to $1"
@@ -46,11 +63,15 @@ configureNamespace() {
4663
}
4764

4865
waitForDeployment() {
66+
if [ ! -z "$1" ]; then
67+
OPNAMESPACE=$1
68+
fi
69+
4970
set +e # allow this next command to fail
50-
kubectl rollout status deploy/porter-operator-controller-manager --namespace porter-operator-system --timeout 30s
71+
kubectl rollout status deploy/porter-operator-controller-manager --namespace $OPNAMESPACE --timeout 30s
5172
if [[ $? != 0 ]]; then
5273
echo "Deployment failed, retrieving logs to troubleshoot"
53-
kubectl logs deploy/porter-operator-controller-manager --namespace porter-operator-system -c manager
74+
kubectl logs deploy/porter-operator-controller-manager --namespace $OPNAMESPACE -c manager
5475
fi
5576
}
5677

installer/vanilla.porter.yaml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ parameters:
6868
default: "13.6.2"
6969
applyTo:
7070
- install
71+
- name: operatorNamespace
72+
description: Namespace to install the operator into
73+
type: string
74+
default: "porter-operator-system"
75+
applyTo:
76+
- install
77+
- upgrade
7178
- name: mongodbVals
7279
description: Helm values file to use when installing the mongodb chart
7380
type: file
@@ -88,6 +95,12 @@ mixins:
8895
- kubernetes
8996

9097
install:
98+
- exec:
99+
description: "Set custom namespace for operator if present"
100+
command: ./helpers.sh
101+
arguments:
102+
- setCustomNamespaceForOperator
103+
- ${bundle.parameters.operatorNamespace}
91104
- exec:
92105
description: "Set manager image reference"
93106
command: ./helpers.sh
@@ -101,7 +114,7 @@ install:
101114
wait: true
102115
- helm3:
103116
description: "Install a mongo database for Porter"
104-
namespace: porter-operator-system
117+
namespace: ${bundle.parameters.operatorNamespace}
105118
name: mongodb
106119
chart: bitnami/mongodb
107120
version: ${bundle.parameters.mongodbChartVersion}
@@ -115,8 +128,15 @@ install:
115128
command: ./helpers.sh
116129
arguments:
117130
- waitForDeployment
131+
- ${bundle.parameters.operatorNamespace}
118132

119133
upgrade:
134+
- exec:
135+
description: "Set custom namespace for operator if present"
136+
command: ./helpers.sh
137+
arguments:
138+
- setCustomNamespaceForOperator
139+
- ${bundle.parameters.operatorNamespace}
120140
- exec:
121141
description: "Set manager image reference"
122142
command: ./helpers.sh

0 commit comments

Comments
 (0)