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

Remove targetNamespace option #2124

Merged
merged 1 commit into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pkg/apis/internal.acorn.io/v1/appinstance.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ type AppInstanceSpec struct {
Secrets []SecretBinding `json:"secrets,omitempty"`
Environment []NameValue `json:"environment,omitempty"`
PublishMode PublishMode `json:"publishMode,omitempty"`
TargetNamespace string `json:"targetNamespace,omitempty"`
Links []ServiceBinding `json:"services,omitempty"`
Publish []PortBinding `json:"ports,omitempty"`
DeployArgs GenericMap `json:"deployArgs,omitempty"`
Expand Down
3 changes: 1 addition & 2 deletions pkg/cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ More Usages:
- Bind the acorn volume named "mydata" into the current app, replacing the volume named "data", See "acorn volumes --help for more info"
acorn run --volume mydata:data .`

var hideRunFlags = []string{"dangerous", "memory", "target-namespace", "secret", "volume", "region", "publish-all",
var hideRunFlags = []string{"dangerous", "memory", "secret", "volume", "region", "publish-all",
"publish", "link", "label", "interval", "env", "compute-class", "annotation", "update", "replace"}

type Run struct {
Expand Down Expand Up @@ -160,7 +160,6 @@ func (s RunArgs) ToOpts() (client.AppRunOptions, error) {
opts.Name = s.Name
opts.Region = s.Region
opts.Profiles = s.Profile
opts.TargetNamespace = s.TargetNamespace
opts.AutoUpgrade = s.AutoUpgrade
opts.NotifyUpgrade = s.NotifyUpgrade
opts.AutoUpgradeInterval = s.Interval
Expand Down
39 changes: 19 additions & 20 deletions pkg/cli/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/spf13/cobra"
)

var hideUpdateFlags = []string{"dangerous", "memory", "target-namespace", "secret", "volume", "region", "publish-all",
var hideUpdateFlags = []string{"dangerous", "memory", "secret", "volume", "region", "publish-all",
"publish", "link", "label", "interval", "env", "compute-class", "annotation"}

func NewUpdate(c CommandContext) *cobra.Command {
Expand All @@ -34,25 +34,24 @@ func NewUpdate(c CommandContext) *cobra.Command {
}

type UpdateArgs struct {
Region string `usage:"Region in which to deploy the app, immutable"`
File string `short:"f" usage:"Name of the build file (default \"DIRECTORY/Acornfile\")"`
Volume []string `usage:"Bind an existing volume (format existing:vol-name,field=value) (ex: pvc-name:app-data)" short:"v" split:"false"`
Secret []string `usage:"Bind an existing secret (format existing:sec-name) (ex: sec-name:app-secret)" short:"s"`
Link []string `usage:"Link external app as a service in the current app (format app-name:container-name)"`
PublishAll *bool `usage:"Publish all (true) or none (false) of the defined ports of application" short:"P"`
Publish []string `usage:"Publish port of application (format [public:]private) (ex 81:80)" short:"p"`
Profile []string `usage:"Profile to assign default values"`
Env []string `usage:"Environment variables to set on running containers" short:"e"`
Label []string `usage:"Add labels to the app and the resources it creates (format [type:][name:]key=value) (ex k=v, containers:k=v)" short:"l"`
Annotation []string `usage:"Add annotations to the app and the resources it creates (format [type:][name:]key=value) (ex k=v, containers:k=v)"`
Dangerous bool `usage:"Automatically approve all privileges requested by the application"`
Output string `usage:"Output API request without creating app (json, yaml)" short:"o"`
TargetNamespace string `usage:"The name of the namespace to be created and deleted for the application resources"`
NotifyUpgrade *bool `usage:"If true and the app is configured for auto-upgrades, you will be notified in the CLI when an upgrade is available and must confirm it"`
AutoUpgrade *bool `usage:"Enabled automatic upgrades."`
Interval string `usage:"If configured for auto-upgrade, this is the time interval at which to check for new releases (ex: 1h, 5m)"`
Memory []string `usage:"Set memory for a workload in the format of workload=memory. Only specify an amount to set all workloads. (ex foo=512Mi or 512Mi)" short:"m"`
ComputeClass []string `usage:"Set computeclass for a workload in the format of workload=computeclass. Specify a single computeclass to set all workloads. (ex foo=example-class or example-class)"`
Region string `usage:"Region in which to deploy the app, immutable"`
File string `short:"f" usage:"Name of the build file (default \"DIRECTORY/Acornfile\")"`
Volume []string `usage:"Bind an existing volume (format existing:vol-name,field=value) (ex: pvc-name:app-data)" short:"v" split:"false"`
Secret []string `usage:"Bind an existing secret (format existing:sec-name) (ex: sec-name:app-secret)" short:"s"`
Link []string `usage:"Link external app as a service in the current app (format app-name:container-name)"`
PublishAll *bool `usage:"Publish all (true) or none (false) of the defined ports of application" short:"P"`
Publish []string `usage:"Publish port of application (format [public:]private) (ex 81:80)" short:"p"`
Profile []string `usage:"Profile to assign default values"`
Env []string `usage:"Environment variables to set on running containers" short:"e"`
Label []string `usage:"Add labels to the app and the resources it creates (format [type:][name:]key=value) (ex k=v, containers:k=v)" short:"l"`
Annotation []string `usage:"Add annotations to the app and the resources it creates (format [type:][name:]key=value) (ex k=v, containers:k=v)"`
Dangerous bool `usage:"Automatically approve all privileges requested by the application"`
Output string `usage:"Output API request without creating app (json, yaml)" short:"o"`
NotifyUpgrade *bool `usage:"If true and the app is configured for auto-upgrades, you will be notified in the CLI when an upgrade is available and must confirm it"`
AutoUpgrade *bool `usage:"Enabled automatic upgrades."`
Interval string `usage:"If configured for auto-upgrade, this is the time interval at which to check for new releases (ex: 1h, 5m)"`
Memory []string `usage:"Set memory for a workload in the format of workload=memory. Only specify an amount to set all workloads. (ex foo=512Mi or 512Mi)" short:"m"`
ComputeClass []string `usage:"Set computeclass for a workload in the format of workload=computeclass. Specify a single computeclass to set all workloads. (ex foo=example-class or example-class)"`
}

type Update struct {
Expand Down
4 changes: 0 additions & 4 deletions pkg/client/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ func ToApp(namespace, image string, opts *AppRunOptions) *apiv1.App {
Environment: opts.Env,
Labels: opts.Labels,
Annotations: opts.Annotations,
TargetNamespace: opts.TargetNamespace,
AutoUpgrade: opts.AutoUpgrade,
NotifyUpgrade: opts.NotifyUpgrade,
AutoUpgradeInterval: opts.AutoUpgradeInterval,
Expand Down Expand Up @@ -154,9 +153,6 @@ func ToAppUpdate(ctx context.Context, c Client, name string, opts *AppUpdateOpti
if opts.Permissions != nil {
app.Spec.Permissions = opts.Permissions
}
if opts.TargetNamespace != "" {
app.Spec.TargetNamespace = opts.TargetNamespace
}
if opts.AutoUpgrade != nil {
app.Spec.AutoUpgrade = opts.AutoUpgrade
}
Expand Down
4 changes: 0 additions & 4 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ type AppUpdateOptions struct {
DeployArgs map[string]any
Stop *bool
Image string
TargetNamespace string
Replace bool // Replace is used to indicate whether the update should be a patch (replace=false: only change specified fields) or a full update (replace=true: reset unspecified fields to defaults)
AutoUpgrade *bool
NotifyUpgrade *bool
Expand All @@ -127,7 +126,6 @@ type AppRunOptions struct {
Publish []v1.PortBinding
Env []v1.NameValue
Profiles []string
TargetNamespace string
DeployArgs map[string]any
Stop *bool
Permissions []v1.Permissions
Expand All @@ -152,7 +150,6 @@ func (a AppRunOptions) ToUpdate() AppUpdateOptions {
Profiles: a.Profiles,
Permissions: a.Permissions,
Env: a.Env,
TargetNamespace: a.TargetNamespace,
AutoUpgrade: a.AutoUpgrade,
NotifyUpgrade: a.NotifyUpgrade,
AutoUpgradeInterval: a.AutoUpgradeInterval,
Expand All @@ -175,7 +172,6 @@ func (a AppUpdateOptions) ToRun() AppRunOptions {
Profiles: a.Profiles,
Permissions: a.Permissions,
Env: a.Env,
TargetNamespace: a.TargetNamespace,
AutoUpgrade: a.AutoUpgrade,
NotifyUpgrade: a.NotifyUpgrade,
AutoUpgradeInterval: a.AutoUpgradeInterval,
Expand Down
39 changes: 2 additions & 37 deletions pkg/controller/appdefinition/namespace.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package appdefinition

import (
"fmt"
"strings"

"github.com/acorn-io/baaah/pkg/router"
Expand All @@ -10,7 +9,6 @@ import (
"github.com/acorn-io/runtime/pkg/labels"
"github.com/rancher/wrangler/pkg/name"
corev1 "k8s.io/api/core/v1"
apierror "k8s.io/apimachinery/pkg/api/errors"
kclient "sigs.k8s.io/controller-runtime/pkg/client"
)

Expand All @@ -23,46 +21,13 @@ func AssignNamespace(req router.Request, resp router.Response) (err error) {
err = nil
}()

if appInstance.Spec.TargetNamespace != "" {
if err := ensureNamespaceOwned(req, appInstance); err != nil {
return err
}
}

if appInstance.Spec.TargetNamespace == "" {
parts := strings.Split(appInstance.Name, ".")
appInstance.Status.Namespace = name.SafeConcatName(parts[len(parts)-1], appInstance.ShortID())
} else {
appInstance.Status.Namespace = appInstance.Spec.TargetNamespace
}
parts := strings.Split(appInstance.Name, ".")
appInstance.Status.Namespace = name.SafeConcatName(parts[len(parts)-1], appInstance.ShortID())

resp.Objects(appInstance)
return nil
}

func ensureNamespaceOwned(req router.Request, appInstance *v1.AppInstance) error {
ns := &corev1.Namespace{}
err := req.Get(ns, "", appInstance.Spec.TargetNamespace)
if apierror.IsNotFound(err) {
return nil
} else if err != nil {
return err
}

if ns.Labels[labels.AcornAppNamespace] != appInstance.Namespace ||
ns.Labels[labels.AcornAppName] != appInstance.Name {
err := 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)
appInstance.Status.Columns.Message = err.Error()
return err
}
return nil
}

func IgnoreTerminatingNamespace(h router.Handler) router.Handler {
return router.HandlerFunc(func(req router.Request, resp router.Response) error {
ns := &corev1.Namespace{}
Expand Down
4 changes: 0 additions & 4 deletions pkg/controller/appdefinition/namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ func TestAssignNamespace(t *testing.T) {
tester.DefaultTest(t, scheme.Scheme, "testdata/assignnamespace", AssignNamespace)
}

func TestAssignTargetNamespace(t *testing.T) {
tester.DefaultTest(t, scheme.Scheme, "testdata/assigntargetnamespace", AssignNamespace)
}

func TestLabelsAnnotationsBasic(t *testing.T) {
tester.DefaultTest(t, scheme.Scheme, "testdata/propagation_basic", namespace.AddNamespace)
}
Expand Down

This file was deleted.

This file was deleted.

6 changes: 0 additions & 6 deletions pkg/openapi/generated/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.