Skip to content

Commit

Permalink
feat: add fields to values
Browse files Browse the repository at this point in the history
  • Loading branch information
matteogastaldello committed Jan 31, 2025
1 parent 5b25bee commit 8e03f36
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 23 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,6 @@ These enviroment varibles can be changed in the Deployment of the composition-dy
| COMPOSITION_CONTROLLER_GROUP | resource api group | |
| COMPOSITION_CONTROLLER_VERSION | resource api version | |
| COMPOSITION_CONTROLLER_RESOURCE | resource plural name | |
| URL_PLURALS | url to krateo pluraliser service | http://bff.krateo-system.svc.cluster.local:8081/api-info/names |
| KRATEO_NAMESPACE | namespace where krateo is installed | krateo-system |
| HELM_REGISTRY_CONFIG_PATH | default helm config path | /tmp |
23 changes: 13 additions & 10 deletions internal/composition/composition.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var (
errReleaseNotFound = errors.New("helm release not found")
errCreateIncomplete = "cannot determine creation result - remove the " + meta.AnnotationKeyExternalCreatePending + " annotation if it is safe to proceed"
helmRegistryConfigPath = env.GetEnvOrDefault("HELM_REGISTRY_CONFIG_PATH", helmclient.DefaultRegistryConfigPath)
krateoNamespace = env.GetEnvOrDefault("KRATEO_NAMESPACE", "krateo-system")
helmRegistryConfigFile = filepath.Join(helmRegistryConfigPath, registry.CredentialsFileBasename)
)

Expand Down Expand Up @@ -267,11 +268,12 @@ func (h *handler) Create(ctx context.Context, mg *unstructured.Unstructured) err
DynamicClient: h.dynamicClient,
Pluralizer: h.pluralizer,
},
HelmClient: hc,
ChartName: pkg.URL,
Resource: mg,
Repo: pkg.Repo,
Version: pkg.Version,
HelmClient: hc,
ChartName: pkg.URL,
Resource: mg,
Repo: pkg.Repo,
Version: pkg.Version,
KrateoNamespace: krateoNamespace,
}
if pkg.RegistryAuth != nil {
opts.Credentials = &helmchart.Credentials{
Expand Down Expand Up @@ -371,11 +373,12 @@ func (h *handler) Update(ctx context.Context, mg *unstructured.Unstructured) err
DynamicClient: h.dynamicClient,
Pluralizer: h.pluralizer,
},
HelmClient: hc,
ChartName: pkg.URL,
Resource: mg,
Repo: pkg.Repo,
Version: pkg.Version,
HelmClient: hc,
ChartName: pkg.URL,
Resource: mg,
Repo: pkg.Repo,
Version: pkg.Version,
KrateoNamespace: krateoNamespace,
}
if pkg.RegistryAuth != nil {
opts.Credentials = &helmchart.Credentials{
Expand Down
28 changes: 22 additions & 6 deletions internal/tools/helmchart/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ type Credentials struct {

type InstallOptions struct {
CheckResourceOptions
HelmClient helmclient.Client
ChartName string
Resource *unstructured.Unstructured
Repo string
Version string
Credentials *Credentials
HelmClient helmclient.Client
ChartName string
Resource *unstructured.Unstructured
Repo string
Version string
Credentials *Credentials
KrateoNamespace string
}

func Install(ctx context.Context, opts InstallOptions) (*release.Release, int64, error) {
Expand Down Expand Up @@ -55,6 +56,21 @@ func Install(ctx context.Context, opts InstallOptions) (*release.Release, int64,
return nil, 0, fmt.Errorf("failed to get GVR: %w", err)
}

dat, err = AddOrUpdateFieldInValues(dat, opts.Resource.GetNamespace(), "global", "compositionNamespace")
if err != nil {
return nil, 0, fmt.Errorf("failed to add compositionNamespace to values: %w", err)
}

Check warning on line 62 in internal/tools/helmchart/install.go

View check run for this annotation

Codecov / codecov/patch

internal/tools/helmchart/install.go#L59-L62

Added lines #L59 - L62 were not covered by tests

dat, err = AddOrUpdateFieldInValues(dat, opts.Resource.GetName(), "global", "compositionName")
if err != nil {
return nil, 0, fmt.Errorf("failed to add compositionName to values: %w", err)
}

Check warning on line 67 in internal/tools/helmchart/install.go

View check run for this annotation

Codecov / codecov/patch

internal/tools/helmchart/install.go#L64-L67

Added lines #L64 - L67 were not covered by tests

dat, err = AddOrUpdateFieldInValues(dat, opts.KrateoNamespace, "global", "krateoNamespace")
if err != nil {
return nil, 0, fmt.Errorf("failed to add krateoNamespace to values: %w", err)
}

Check warning on line 72 in internal/tools/helmchart/install.go

View check run for this annotation

Codecov / codecov/patch

internal/tools/helmchart/install.go#L69-L72

Added lines #L69 - L72 were not covered by tests

dat, err = AddOrUpdateFieldInValues(dat, uid, "global", "compositionId")
if err != nil {
return nil, 0, fmt.Errorf("failed to add compositionId to values: %w", err)
Expand Down
28 changes: 22 additions & 6 deletions internal/tools/helmchart/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ import (

type UpdateOptions struct {
CheckResourceOptions
HelmClient helmclient.Client
ChartName string
Version string
Resource *unstructured.Unstructured
Repo string
Credentials *Credentials
HelmClient helmclient.Client
ChartName string
Version string
Resource *unstructured.Unstructured
Repo string
Credentials *Credentials
KrateoNamespace string
}

func Update(ctx context.Context, opts UpdateOptions) error {
Expand Down Expand Up @@ -53,6 +54,21 @@ func Update(ctx context.Context, opts UpdateOptions) error {
return fmt.Errorf("failed to get GVR: %w", err)
}

dat, err = AddOrUpdateFieldInValues(dat, opts.Resource.GetNamespace(), "global", "compositionNamespace")
if err != nil {
return fmt.Errorf("failed to add compositionNamespace to values: %w", err)
}

Check warning on line 60 in internal/tools/helmchart/update.go

View check run for this annotation

Codecov / codecov/patch

internal/tools/helmchart/update.go#L57-L60

Added lines #L57 - L60 were not covered by tests

dat, err = AddOrUpdateFieldInValues(dat, opts.Resource.GetName(), "global", "compositionName")
if err != nil {
return fmt.Errorf("failed to add compositionName to values: %w", err)
}

Check warning on line 65 in internal/tools/helmchart/update.go

View check run for this annotation

Codecov / codecov/patch

internal/tools/helmchart/update.go#L62-L65

Added lines #L62 - L65 were not covered by tests

dat, err = AddOrUpdateFieldInValues(dat, opts.KrateoNamespace, "global", "krateoNamespace")
if err != nil {
return fmt.Errorf("failed to add krateoNamespace to values: %w", err)
}

Check warning on line 70 in internal/tools/helmchart/update.go

View check run for this annotation

Codecov / codecov/patch

internal/tools/helmchart/update.go#L67-L70

Added lines #L67 - L70 were not covered by tests

dat, err = AddOrUpdateFieldInValues(dat, uid, "global", "compositionId")
if err != nil {
return fmt.Errorf("failed to add compositionId to values: %w", err)
Expand Down
4 changes: 4 additions & 0 deletions scripts/build_local.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

ko build -t latest --base-import-paths . --local

0 comments on commit 8e03f36

Please sign in to comment.