Skip to content

Commit

Permalink
Fix Application Provisioning (#46)
Browse files Browse the repository at this point in the history
Handle unified resource metadata.
  • Loading branch information
spjmurray authored Jun 4, 2024
1 parent 3c035f1 commit f413194
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 28 deletions.
4 changes: 2 additions & 2 deletions charts/core/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: A Helm chart for deploying Unikorn Core

type: application

version: v0.1.39
appVersion: v0.1.39
version: v0.1.40
appVersion: v0.1.40

icon: https://assets.unikorn-cloud.org/images/logos/dark-on-light/icon.svg
15 changes: 2 additions & 13 deletions pkg/provisioners/application/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
unikornv1 "github.com/unikorn-cloud/core/pkg/apis/unikorn/v1alpha1"
"github.com/unikorn-cloud/core/pkg/cd"
clientlib "github.com/unikorn-cloud/core/pkg/client"
"github.com/unikorn-cloud/core/pkg/constants"
"github.com/unikorn-cloud/core/pkg/provisioners"
"github.com/unikorn-cloud/core/pkg/util"

Expand Down Expand Up @@ -79,14 +80,6 @@ func (p *Provisioner) InNamespace(namespace string) *Provisioner {
return p
}

// WithApplicationName allows the application name to be modified, rather than using
// application.Name.
func (p *Provisioner) WithApplicationName(name string) *Provisioner {
p.Name = name

return p
}

// WithGenerator registers an object that can generate implicit configuration where
// you cannot do it all from the default set of arguments.
func (p *Provisioner) WithGenerator(generator interface{}) *Provisioner {
Expand Down Expand Up @@ -293,11 +286,7 @@ func (p *Provisioner) initialize(ctx context.Context) error {
return err
}

// This may have been manually overridden.
// TODO: this is only used by the clusteropenstack...
if p.Name == "" {
p.Name = application.Name
}
p.Name = application.Labels[constants.NameLabel]

version, err := application.GetVersion(*ref.Version)
if err != nil {
Expand Down
42 changes: 29 additions & 13 deletions pkg/provisioners/application/provisioner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/unikorn-cloud/core/pkg/cd"
"github.com/unikorn-cloud/core/pkg/cd/mock"
coreclient "github.com/unikorn-cloud/core/pkg/client"
"github.com/unikorn-cloud/core/pkg/constants"
"github.com/unikorn-cloud/core/pkg/provisioners"
"github.com/unikorn-cloud/core/pkg/provisioners/application"
mockprovisioners "github.com/unikorn-cloud/core/pkg/provisioners/mock"
Expand Down Expand Up @@ -91,17 +92,17 @@ func mustNewTestContext(t *testing.T, objects ...client.Object) *testContext {
}

const (
applicationName = "test"
overrideApplicationName = "testinate"
repo = "foo"
chart = "bar"
version = "baz"
applicationID = "c785837a-7412-49a6-ac7e-6d75ab6ca577"
applicationName = "test"
repo = "foo"
chart = "bar"
version = "baz"
)

func getApplicationReference(ctx context.Context) (*unikornv1.ApplicationReference, error) {
ref := &unikornv1.ApplicationReference{
Kind: util.ToPointer(unikornv1.ApplicationReferenceKindHelm),
Name: util.ToPointer(applicationName),
Name: util.ToPointer(applicationID),
Version: util.ToPointer(version),
}

Expand All @@ -115,7 +116,10 @@ func TestApplicationCreateHelm(t *testing.T) {

app := &unikornv1.HelmApplication{
ObjectMeta: metav1.ObjectMeta{
Name: applicationName,
Name: applicationID,
Labels: map[string]string{
constants.NameLabel: applicationName,
},
},
Spec: unikornv1.HelmApplicationSpec{
Versions: []unikornv1.HelmApplicationVersion{
Expand Down Expand Up @@ -176,7 +180,10 @@ func TestApplicationCreateHelmExtended(t *testing.T) {

app := &unikornv1.HelmApplication{
ObjectMeta: metav1.ObjectMeta{
Name: applicationName,
Name: applicationID,
Labels: map[string]string{
constants.NameLabel: applicationName,
},
},
Spec: unikornv1.HelmApplicationSpec{
Versions: []unikornv1.HelmApplicationVersion{
Expand Down Expand Up @@ -221,7 +228,7 @@ func TestApplicationCreateHelmExtended(t *testing.T) {
r.EXPECT().ID().Return(remoteID)

driverAppID := &cd.ResourceIdentifier{
Name: overrideApplicationName,
Name: applicationName,
Labels: newManagedResourceLabels(),
}

Expand Down Expand Up @@ -252,7 +259,7 @@ func TestApplicationCreateHelmExtended(t *testing.T) {

driver.EXPECT().CreateOrUpdateHelmApplication(ctx, driverAppID, driverApp).Return(provisioners.ErrYield)

provisioner := application.New(getApplicationReference).WithApplicationName(overrideApplicationName).AllowDegraded()
provisioner := application.New(getApplicationReference).AllowDegraded()
provisioner.OnRemote(r)

assert.ErrorIs(t, provisioner.Provision(ctx), provisioners.ErrYield)
Expand All @@ -267,7 +274,10 @@ func TestApplicationCreateGit(t *testing.T) {

app := &unikornv1.HelmApplication{
ObjectMeta: metav1.ObjectMeta{
Name: applicationName,
Name: applicationID,
Labels: map[string]string{
constants.NameLabel: applicationName,
},
},
Spec: unikornv1.HelmApplicationSpec{
Versions: []unikornv1.HelmApplicationVersion{
Expand Down Expand Up @@ -382,7 +392,10 @@ func TestApplicationCreateMutate(t *testing.T) {

app := &unikornv1.HelmApplication{
ObjectMeta: metav1.ObjectMeta{
Name: applicationName,
Name: applicationID,
Labels: map[string]string{
constants.NameLabel: applicationName,
},
},
Spec: unikornv1.HelmApplicationSpec{
Versions: []unikornv1.HelmApplicationVersion{
Expand Down Expand Up @@ -455,7 +468,10 @@ func TestApplicationDeleteNotFound(t *testing.T) {

app := &unikornv1.HelmApplication{
ObjectMeta: metav1.ObjectMeta{
Name: applicationName,
Name: applicationID,
Labels: map[string]string{
constants.NameLabel: applicationName,
},
},
Spec: unikornv1.HelmApplicationSpec{
Versions: []unikornv1.HelmApplicationVersion{
Expand Down

0 comments on commit f413194

Please sign in to comment.