Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
fix: change docs and error message for pre-created namespace deployme…
Browse files Browse the repository at this point in the history
…nt (#785)

fix: change docs and error message for precreated namespace deployment

Signed-off-by: Joshua Silverio <joshua@acorn.io>
Co-authored-by: Craig Jellick <craig.jellick@gmail.com>
  • Loading branch information
jsilverio22 and cjellick committed Nov 1, 2022
1 parent 3ab6fb4 commit 85872b8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
27 changes: 27 additions & 0 deletions docs/docs/50-running/50-namespaces-and-service-accounts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
title: Namespaces and Service Accounts
---
## Namespaces

By design Acorn will run apps under the `acorn` namespace. If you are planning to deploy an app to a pre-created namespace you will need to label it explicitly.

#### To label :

```shell
kubectl label namespaces <pre-created-namespace> acorn.io/app-name=<test-app>
kubectl label namespaces <pre-created-namespace> acorn.io/app-namespace=acorn
```
#### To verify :
```shell
acorn run --target-namespace <pre-created-namespace> -n <test-app> -P ghcr.io/acorn-io/library/hello-world
acorn % kubectl get pods -n ns-test-app
NAME READY STATUS RESTARTS AGE
webapp-556947c87d-gt97r 1/1 Running 0 3m54s

```
:::caution
When the app is removed the namespace will also be deleted.

## Service Accounts

All Kubernetes deployments launched as part of an Acorn will have a service account attached named "acorn"
11 changes: 6 additions & 5 deletions pkg/controller/appdefinition/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ func ensureNamespaceOwned(req router.Request, appInstance *v1.AppInstance) error

if ns.Labels[labels.AcornAppNamespace] != appInstance.Namespace ||
ns.Labels[labels.AcornAppName] != appInstance.Name {
return fmt.Errorf("can not use namespace %s, existing namespace must have labels [%s=%s] and [%s=%s]."+
" And namespace will be deleted when the app is deleted",
appInstance.Spec.TargetNamespace,
ns.Labels[labels.AcornAppNamespace], appInstance.Namespace,
ns.Labels[labels.AcornAppName], appInstance.Name)
return fmt.Errorf("can not use namespace %s, existing namespace must have labels "+
"acorn.io/app-namespace"+" and acorn.io/app-name (Apply Using: kubectl label namespaces %s acorn.io/app-name=%s "+
"kubectl label namespaces %s acorn.io/app-namespace=acorn) "+
"Namespace will be deleted when the app is deleted",
appInstance.Spec.TargetNamespace, appInstance.Spec.TargetNamespace, appInstance.Name,
appInstance.Spec.TargetNamespace)
}
return nil
}
Expand Down

0 comments on commit 85872b8

Please sign in to comment.