Resolution
Rename the Kubernetes agent's namespace to follow the "octopus-agent-" or "octopus-worker-" naming convention (e.g. "octopus-agent-my-agent" or "octopus-worker-new").
Alternatively, alter either the TARGET_NAMESPACES or TARGET_NAMESPACE_REGEX within the manager.yaml to accept the namespace that you want to match within your pod.
Symptom
"error": "stage execution failed: no target namespaces in plan"
Scope: when this is the right article
This article applies when:
- Kubernetes agent is involved
- The agent was just recently installed along with the permissions controller
- The error in the "Symptom" section is coming up when trying to utilize the Kubernetes agent for any deployment within Octopus.
Cause
The Octopus permissions controller is attempting to match the Kubernetes agent namespace with the regex ^octopus-(agent|worker)-.* by default. This means that the Kubernetes agent namespace naming in the pod must be something along the lines of:
- octopus-agent-
- octopus-worker-
If it is anything, but this style, the permissions controller cannot match the namespace by default.
Diagnosis and fix
Check the Kubernetes agent namespace naming convention to make sure it follows either "octopus-agent-" or "octopus-worker-" naming conventions. You can check this by running the following kubectl command and replacing the with the name of your Kubernetes Agent's pod name:
kubectl get pods -A | grep <pod-name>
If you identify that your agent pod's namespace does not follow the naming convention (e.g. "octopus-agent", "k8s-agent", "new-worker", etc.) then you can either:
- Recommended: rename the agent pod's namespace to follow the default regex naming convention (e.g. "octopus-agent-my-agent", "octopus-agent-new", "octopus-worker-aws-worker", "octopus-worker-new", etc.). This must always have a trailing single dash after "octopus-agent-" or "octopus-worker-" before adding your own text.
- alter the permissions-controllers manager YAML to change the TARGET_NAMESPACES environment variable to include your namespaces (comma separated list).
- alter the permissions-controllers manager YAML to change the TARGET_NAMESPACE_REGEX environment variable to match your current namespace naming convention.
Verify
Once the namespace is changed (or the environment variables have been altered), you can re-run any policy changes, or deployments, against the agent to check that it is working. Any execution against the cluster with the Kubernetes agent should pass the planning stage correctly now, and go into the execution phase.