Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ability to install Operator with an alternate namcespace than the default (porter-operator-system) #191

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

SubZer0MS
Copy link

What does this change

Added functionality of being able to specify an alternate namespace than the default (porter-operator-system) where the Operator is installed by passing in "--param operatorNamespace=operator-ns-name-here" to the operator porter install command.

What issue does it fix

Closes # (issue)

Notes for the reviewer

I'll handle the second issue which is discussed there (ability to install Operator with kustomize, without porter) in a separate PR.

Checklist

  • Did you write tests?
  • Did you write documentation?
  • Did you make any API changes? Update the corresponding API documentation.

@SubZer0MS SubZer0MS changed the title Mihsar operator ability to install Operator with an alternate namcespace than the default (porter-operator-system) Mar 30, 2023
@carolynvs
Copy link
Member

https://getporter.org/contribute/guide/#signing-your-commits explains how to get the DCO check to pass

Signed-off-by: Mihai Sarbulescu <mihai.sarbulescu@gmail.com>
Signed-off-by: Mihai Sarbulescu <mihai.sarbulescu@gmail.com>
@carolynvs carolynvs self-assigned this Apr 27, 2023
Copy link
Member

@carolynvs carolynvs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies for the slow review, I didn't see that you'd updated the PR after my last comment. It really helps to leave a comment on the PR when you make a change or push a commit that is ready for me to look at as it's easy to miss the notification that a new commit has been pushed to the PR.

I see the tests are not passing, let's get the current batch of comments addressed and see if that resolves it first.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The configureNamespace function is used by the configureNamespace custom action for the bundle, it sets up a namespace for use with the operator with required configuration such as a porter configuration file. By default we use the contents of installer/manifests/namespace/defaults/porter-config-spec.yaml. In that file, we reference the in-cluster mongodb service that is installed in the operator namespace and it's hard-coded to porter-operator-system.

The configureNamespace helper function should also update that file when a custom porter configuration file was not specified to use the custom operator namespace.

storage:
  - name: "in-cluster-mongodb"
    plugin: "mongodb"
    config:
      url: "mongodb://mongodb.TODO-OPERATOR-NAMESPACE.svc.cluster.local"


setCustomNamespaceForOperator() {
if [ -z "$1" ]; then
echo "No namespace specified, using default $OPNAMESPACE"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's always be clear which namespace we are referring to in these messages, because we have both the "porter operator namespace" and also a namespace that is created and configured by the configureNamespace custom action in the bundle.

Suggested change
echo "No namespace specified, using default $OPNAMESPACE"
echo "No porter operator namespace specified, using default $OPNAMESPACE"

echo "No namespace specified, using default $OPNAMESPACE"
else
OPNAMESPACE=$1
echo "Using custom namespace $OPNAMESPACE"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
echo "Using custom namespace $OPNAMESPACE"
echo "Using custom porter operator namespace $OPNAMESPACE"

fi

# Replace the namespace in the operator.yaml
echo "Setting namespace to $OPNAMESPACE"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
echo "Setting namespace to $OPNAMESPACE"
echo "Setting porter operator namespace to $OPNAMESPACE"

Comment on lines +75 to +77
applyTo:
- install
- upgrade
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The configureNamespace custom action will also need the porter operator namespace parameter.

Suggested change
applyTo:
- install
- upgrade
applyTo:
- install
- upgrade
- configureNamespace

@@ -88,6 +95,12 @@ mixins:
- kubernetes

install:
- exec:
description: "Set custom namespace for operator if present"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
description: "Set custom namespace for operator if present"
description: "Set custom namespace for operator

The parameter operatorNamespace will always be populated. So if it's not customized by the user it will just have the default value. Since this step always runs and the helper script always runs kustomize, let's make it clear that this logic always runs.

@@ -1,6 +1,23 @@
#!/usr/bin/env bash
set -euo pipefail

OPNAMESPACE="porter-operator-system"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works but I wanted you to know about a porter feature in case that affects how you'd like to implement this.

The parameter operatorNamespace is always populated, it will have the default value if not specified by the user, and a corresponding environment variable, OPERATORNAMESPACE set. There isn't a need to define OPNAMESPACE, pass the parameter as an argument to each helper function, and initialize OPNAMESPACE in each function. You can just use OPERATORNAMESPACE.

@@ -334,7 +334,7 @@ func Deploy() {
buildPorterCmd("credentials", "apply", "hack/creds.yaml", "-n=operator").Must().RunV()
}
bundleRef := Env.BundlePrefix + meta.Version
installCmd := buildPorterCmd("install", "operator", "-r", bundleRef, "-c=kind", "--force", "-n=operator").Must()
installCmd := buildPorterCmd("install", "operator", "-r", bundleRef, "-c=kind", "--force", "-n=operator", "--param", "operatorNamespace="+operatorNamespace).Must()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's follow the pattern for allowing the developer to customize development parameters, like PORTER_AGENT_REPOSITORY, using local environment variables instead of requiring changes to the code.

The function applyHackParameters should be updated along with the hack/dev-build-params.yaml to set the operatorNamespace parameter from PORTER_OPERATOR_NAMESPACE on the local machine.

@carolynvs
Copy link
Member

Heads up that mage build is failing. I've submitted a PR to get it working again and it's easy enough to patch locally to use debian stable until it's merged.

#201

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🔖 Ready
Development

Successfully merging this pull request may close these issues.

2 participants