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

Commit

Permalink
Add project instances
Browse files Browse the repository at this point in the history
There are a few situations where we need a buffer between a project
being deleted and the corresponding namespace being deleted. One such
scenario is ensuring that delete jobs run when a project is deleted.

This change adds a project instance, which is this buffer. Using the
project instance, we can ensure that all apps are successfully cleaned
up before the namespace is deleted. This should also give the user the
ability to use the ignore-cleanup functionality when deleting a project.

Changes are also made to the integration tests to use project instances
instead of namespaces.

Signed-off-by: Donnie Adams <[email protected]>
  • Loading branch information
thedadams committed Jul 7, 2023
1 parent 26fd3b4 commit 0b9b373
Show file tree
Hide file tree
Showing 85 changed files with 1,169 additions and 1,111 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
cuelang.org/go v0.5.0
github.com/AlecAivazis/survey/v2 v2.3.6
github.com/acorn-io/aml v0.0.0-20230707055340-d9d7a8c927b2
github.com/acorn-io/baaah v0.0.0-20230628211933-3f682344a78d
github.com/acorn-io/baaah v0.0.0-20230707151126-5d519d272865
github.com/acorn-io/mink v0.0.0-20230523184405-ceaaa366d500
github.com/acorn-io/namegenerator v0.0.0-20220915160418-9e3d5a0ffe78
github.com/adrg/xdg v0.4.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d h1:licZJFw2RwpH
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d/go.mod h1:asat636LX7Bqt5lYEZ27JNDcqxfjdBQuJ/MM4CN/Lzo=
github.com/acorn-io/aml v0.0.0-20230707055340-d9d7a8c927b2 h1:zx1YhJI+jecZ1nQ3MzFRblMU4KdACUG8DQfd0zB9XvY=
github.com/acorn-io/aml v0.0.0-20230707055340-d9d7a8c927b2/go.mod h1:UEx5RRLFjryCEHN2pM59+d8A0mPJ3VAxggJOTzPymwg=
github.com/acorn-io/baaah v0.0.0-20230628211933-3f682344a78d h1:a+geMqB3U52a4+iMmLZ9R/EXkgxrp0QCetoqLAUnTD8=
github.com/acorn-io/baaah v0.0.0-20230628211933-3f682344a78d/go.mod h1:LtwaWrYK/VuGptWxeD5Sgl0sgJV1ksicpTzyLilow1U=
github.com/acorn-io/baaah v0.0.0-20230707151126-5d519d272865 h1:BPPGCEBgPxn7crFFWqLDJUlzdHQ23olFkdUqlXd3KA8=
github.com/acorn-io/baaah v0.0.0-20230707151126-5d519d272865/go.mod h1:LtwaWrYK/VuGptWxeD5Sgl0sgJV1ksicpTzyLilow1U=
github.com/acorn-io/mink v0.0.0-20230523184405-ceaaa366d500 h1:tiM36bM+iMWuW9HM+YlM1GfNDXC7f565z8Be5epO0qM=
github.com/acorn-io/mink v0.0.0-20230523184405-ceaaa366d500/go.mod h1:y6aYj2dF/SlU205bDfA43Y5c9sa/aYr4X5GDqYJzJTU=
github.com/acorn-io/namegenerator v0.0.0-20220915160418-9e3d5a0ffe78 h1:5zs9L/CXNkuTdJSbhFWczAorbmx67nqlqswx5CQi7XI=
Expand Down
14 changes: 7 additions & 7 deletions integration/build/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ func TestBuildDefault(t *testing.T) {
func TestMultiArch(t *testing.T) {
helper.StartController(t)
cfg := helper.StartAPI(t)
ns := helper.TempNamespace(t, helper.MustReturn(k8sclient.Default))
project := helper.TempProject(t, helper.MustReturn(k8sclient.Default))
kclient := helper.MustReturn(k8sclient.Default)
c, err := client.New(cfg, "", ns.Name)
c, err := client.New(cfg, "", project.Name)
if err != nil {
t.Fatal()
}
Expand Down Expand Up @@ -204,7 +204,7 @@ func TestMultiArch(t *testing.T) {
t.Fatal(err)
}

opts, err := images.GetAuthenticationRemoteOptions(context.Background(), kclient, ns.Name, remote.WithTransport(transport))
opts, err := images.GetAuthenticationRemoteOptions(context.Background(), kclient, project.Name, remote.WithTransport(transport))
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -234,8 +234,8 @@ func TestMultiArch(t *testing.T) {
func TestBuildNestedAcornWithLocalImage(t *testing.T) {
helper.StartController(t)
cfg := helper.StartAPI(t)
ns := helper.TempNamespace(t, helper.MustReturn(k8sclient.Default))
c, err := client.New(cfg, "", ns.Name)
project := helper.TempProject(t, helper.MustReturn(k8sclient.Default))
c, err := client.New(cfg, "", project.Name)
if err != nil {
t.Fatal(err)
}
Expand All @@ -261,8 +261,8 @@ func TestBuildNestedAcornWithLocalImage(t *testing.T) {
assert.Equal(t, strings.Split(nestedImage.ImageData.Acorns["nginx"].Image, "sha256:")[1], image)

// create a second project and make sure we can't access the local image from the first project
ns2 := helper.TempNamespace(t, helper.MustReturn(k8sclient.Default))
c2, err := client.New(cfg, "", ns2.Name)
project2 := helper.TempProject(t, helper.MustReturn(k8sclient.Default))
c2, err := client.New(cfg, "", project2.Name)
if err != nil {
t.Fatal(err)
}
Expand Down
52 changes: 26 additions & 26 deletions integration/client/apps/apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ func TestAppStartStop(t *testing.T) {

ctx := helper.GetCTX(t)
kclient := helper.MustReturn(kclient.Default)
ns := helper.TempNamespace(t, kclient)
project := helper.TempProject(t, kclient)

imageID := client2.NewImage(t, ns.Name)
imageID := client2.NewImage(t, project.Name)

c, err := client.New(restConfig, "", ns.Name)
c, err := client.New(restConfig, "", project.Name)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -67,11 +67,11 @@ func TestAppDelete(t *testing.T) {

ctx := helper.GetCTX(t)
kclient := helper.MustReturn(kclient.Default)
ns := helper.TempNamespace(t, kclient)
project := helper.TempProject(t, kclient)

imageID := client2.NewImage(t, ns.Name)
imageID := client2.NewImage(t, project.Name)

c, err := client.New(restConfig, "", ns.Name)
c, err := client.New(restConfig, "", project.Name)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -103,12 +103,12 @@ func TestAppUpdate(t *testing.T) {

ctx := helper.GetCTX(t)
kclient := helper.MustReturn(kclient.Default)
ns := helper.TempNamespace(t, kclient)
project := helper.TempProject(t, kclient)

imageID := client2.NewImage(t, ns.Name)
imageID2 := client2.NewImage2(t, ns.Name)
imageID := client2.NewImage(t, project.Name)
imageID2 := client2.NewImage2(t, project.Name)

c, err := client.New(restConfig, "", ns.Name)
c, err := client.New(restConfig, "", project.Name)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -316,11 +316,11 @@ func TestAppGet(t *testing.T) {

ctx := helper.GetCTX(t)
kclient := helper.MustReturn(kclient.Default)
ns := helper.TempNamespace(t, kclient)
project := helper.TempProject(t, kclient)

imageID := client2.NewImage(t, ns.Name)
imageID := client2.NewImage(t, project.Name)

c, err := client.New(restConfig, "", ns.Name)
c, err := client.New(restConfig, "", project.Name)
if err != nil {
t.Fatal(err)
}
Expand All @@ -345,11 +345,11 @@ func TestAppList(t *testing.T) {

ctx := helper.GetCTX(t)
kclient := helper.MustReturn(kclient.Default)
ns := helper.TempNamespace(t, kclient)
project := helper.TempProject(t, kclient)

imageID := client2.NewImage(t, ns.Name)
imageID := client2.NewImage(t, project.Name)

c, err := client.New(restConfig, "", ns.Name)
c, err := client.New(restConfig, "", project.Name)
if err != nil {
t.Fatal(err)
}
Expand All @@ -376,11 +376,11 @@ func TestAppLog(t *testing.T) {

ctx := helper.GetCTX(t)
kclient := helper.MustReturn(kclient.Default)
ns := helper.TempNamespace(t, kclient)
project := helper.TempProject(t, kclient)

imageID := client2.NewImage(t, ns.Name)
imageID := client2.NewImage(t, project.Name)

c, err := client.New(restConfig, "", ns.Name)
c, err := client.New(restConfig, "", project.Name)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -421,11 +421,11 @@ func TestAppRun(t *testing.T) {

ctx := helper.GetCTX(t)
kclient := helper.MustReturn(kclient.Default)
ns := helper.TempNamespace(t, kclient)
project := helper.TempProject(t, kclient)

imageID := client2.NewImage(t, ns.Name)
imageID := client2.NewImage(t, project.Name)

c, err := client.New(restConfig, "", ns.Name)
c, err := client.New(restConfig, "", project.Name)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -455,7 +455,7 @@ func TestAppRun(t *testing.T) {
t.Fatal(err)
}

assert.Equal(t, ns.Name, app.Namespace)
assert.Equal(t, project.Name, app.Namespace)
assert.NotEqual(t, "", app.Name)
assert.Equal(t, v1.PublishModeAll, app.Spec.PublishMode)
assert.Equal(t, "volume", app.Spec.Volumes[0].Volume)
Expand All @@ -469,11 +469,11 @@ func TestAppRunImageVariations(t *testing.T) {

ctx := helper.GetCTX(t)
kclient := helper.MustReturn(kclient.Default)
ns := helper.TempNamespace(t, kclient)
project := helper.TempProject(t, kclient)

imageID := client2.NewImage(t, ns.Name)
imageID := client2.NewImage(t, project.Name)

c, err := client.New(restConfig, "", ns.Name)
c, err := client.New(restConfig, "", project.Name)
if err != nil {
t.Fatal(err)
}
Expand Down
8 changes: 4 additions & 4 deletions integration/client/apps/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ func TestUpdatePull(t *testing.T) {

ctx := helper.GetCTX(t)
kclient := helper.MustReturn(kclient.Default)
ns := helper.TempNamespace(t, kclient)
project := helper.TempProject(t, kclient)

c, err := client.New(restConfig, "", ns.Name)
c, err := client.New(restConfig, "", project.Name)
if err != nil {
t.Fatal(err)
}

imageID := client2.NewImage(t, ns.Name)
imageID := client2.NewImage(t, project.Name)
err = c.ImageTag(ctx, imageID, "foo")
if err != nil {
t.Fatal(err)
Expand All @@ -41,7 +41,7 @@ func TestUpdatePull(t *testing.T) {
assert.NotEmpty(t, app.Status.Namespace)
assert.Equal(t, app.Status.AppImage.ID, imageID)

imageID2 := client2.NewImage2(t, ns.Name)
imageID2 := client2.NewImage2(t, project.Name)
err = c.ImageTag(ctx, imageID2, "foo:latest")
if err != nil {
t.Fatal(err)
Expand Down
12 changes: 6 additions & 6 deletions integration/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

func TestAppsSSA(t *testing.T) {
cfg := helper.StartAPI(t)
c, ns := helper.ClientAndNamespace(t)
c, project := helper.ClientAndProject(t)
ctx := helper.GetCTX(t)

dyn, err := dynamic.NewForConfig(cfg)
Expand All @@ -42,7 +42,7 @@ func TestAppsSSA(t *testing.T) {
},
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Namespace: ns.Name,
Namespace: project.Name,
},
Spec: v1.AppInstanceSpec{
Image: image.ID,
Expand All @@ -53,7 +53,7 @@ func TestAppsSSA(t *testing.T) {
}

_, err = dyn.Resource(apiv1.SchemeGroupVersion.WithResource("apps")).
Namespace(ns.Name).
Namespace(project.Name).
Patch(ctx, "test", types.ApplyPatchType, appBytes, metav1.PatchOptions{
FieldManager: "unit-test",
})
Expand All @@ -73,7 +73,7 @@ func TestFriendlyNameInContainer(t *testing.T) {
helper.StartController(t)
cfg := helper.StartAPI(t)

c, ns := helper.ClientAndNamespace(t)
c, project := helper.ClientAndProject(t)
ctx := helper.GetCTX(t)
client, err := k8sclient.New(cfg)
if err != nil {
Expand All @@ -90,7 +90,7 @@ func TestFriendlyNameInContainer(t *testing.T) {
appInstance := &apiv1.App{
ObjectMeta: metav1.ObjectMeta{
GenerateName: "simple-app",
Namespace: ns.Name,
Namespace: project.Name,
Labels: map[string]string{
labels.AcornManaged: "true",
},
Expand All @@ -109,7 +109,7 @@ func TestFriendlyNameInContainer(t *testing.T) {
return obj.Status.AppStatus.Containers["default"].ReadyReplicaCount == 1
})

c, err = hclient.New(cfg, "", ns.Name)
c, err = hclient.New(cfg, "", project.Name)
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions integration/client/computeclass/computeclass_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import (
func TestCreatingComputeClasses(t *testing.T) {
helper.StartController(t)
cfg := helper.StartAPI(t)
ns := helper.TempNamespace(t, helper.MustReturn(kclient.Default))
project := helper.TempProject(t, helper.MustReturn(kclient.Default))
kclient := helper.MustReturn(kclient.Default)
c, err := client.New(cfg, "", ns.Name)
c, err := client.New(cfg, "", project.Name)
if err != nil {
t.Fatal(err)
}
Expand Down
36 changes: 18 additions & 18 deletions integration/client/containers/containers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ func TestContainerList(t *testing.T) {
t.Fatal(err)
}
kclient := helper.MustReturn(kclient.Default)
ns := helper.TempNamespace(t, kclient)
project := helper.TempProject(t, kclient)

c, err := client.New(restConfig, "", ns.Name)
c, err := client.New(restConfig, "", project.Name)
if err != nil {
t.Fatal(err)
}

imageID := client2.NewImage(t, ns.Name)
imageID := client2.NewImage(t, project.Name)
app, err := c.AppRun(ctx, imageID, nil)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -61,14 +61,14 @@ func TestContainerDelete(t *testing.T) {
t.Fatal(err)
}
kclient := helper.MustReturn(kclient.Default)
ns := helper.TempNamespace(t, kclient)
project := helper.TempProject(t, kclient)

c, err := client.New(restConfig, "", ns.Name)
c, err := client.New(restConfig, "", project.Name)
if err != nil {
t.Fatal(err)
}

imageID := client2.NewImage(t, ns.Name)
imageID := client2.NewImage(t, project.Name)
app, err := c.AppRun(ctx, imageID, nil)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -109,14 +109,14 @@ func TestContainerGet(t *testing.T) {
t.Fatal(err)
}
kclient := helper.MustReturn(kclient.Default)
ns := helper.TempNamespace(t, kclient)
project := helper.TempProject(t, kclient)

c, err := client.New(restConfig, "", ns.Name)
c, err := client.New(restConfig, "", project.Name)
if err != nil {
t.Fatal(err)
}

imageID := client2.NewImage(t, ns.Name)
imageID := client2.NewImage(t, project.Name)
app, err := c.AppRun(ctx, imageID, nil)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -153,14 +153,14 @@ func TestContainerExec(t *testing.T) {
t.Fatal(err)
}
kclient := helper.MustReturn(kclient.Default)
ns := helper.TempNamespace(t, kclient)
project := helper.TempProject(t, kclient)

c, err := client.New(restConfig, "", ns.Name)
c, err := client.New(restConfig, "", project.Name)
if err != nil {
t.Fatal(err)
}

imageID := client2.NewImage(t, ns.Name)
imageID := client2.NewImage(t, project.Name)
app, err := c.AppRun(ctx, imageID, nil)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -207,14 +207,14 @@ func TestContainerDebugExec(t *testing.T) {
t.Fatal(err)
}
kclient := helper.MustReturn(kclient.Default)
ns := helper.TempNamespace(t, kclient)
project := helper.TempProject(t, kclient)

c, err := client.New(restConfig, "", ns.Name)
c, err := client.New(restConfig, "", project.Name)
if err != nil {
t.Fatal(err)
}

imageID := client2.NewImage(t, ns.Name)
imageID := client2.NewImage(t, project.Name)
app, err := c.AppRun(ctx, imageID, nil)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -263,14 +263,14 @@ func TestContainerWithSidecarExec(t *testing.T) {
t.Fatal(err)
}
kclient := helper.MustReturn(kclient.Default)
ns := helper.TempNamespace(t, kclient)
project := helper.TempProject(t, kclient)

c, err := client.New(restConfig, "", ns.Name)
c, err := client.New(restConfig, "", project.Name)
if err != nil {
t.Fatal(err)
}

imageID := client2.NewImageWithSidecar(t, ns.Name)
imageID := client2.NewImageWithSidecar(t, project.Name)
app, err := c.AppRun(ctx, imageID, nil)
if err != nil {
t.Fatal(err)
Expand Down
Loading

0 comments on commit 0b9b373

Please sign in to comment.