Skip to content
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
51 changes: 48 additions & 3 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,15 @@ type TargetCluster struct {
}

type Providers struct {
ClusterProviders []string `json:"clusterProviders"`
ServiceProviders []string `json:"serviceProviders"`
PlatformServices []string `json:"platformServices"`
ClusterProviders []Provider `json:"clusterProviders"`
ServiceProviders []Provider `json:"serviceProviders"`
PlatformServices []Provider `json:"platformServices"`
}

type Provider struct {
Name string `json:"name"`
Config json.RawMessage `json:"config"`
ConfigParsed map[string]interface{}
}

type OpenMCPOperator struct {
Expand Down Expand Up @@ -96,5 +102,44 @@ func (c *BootstrapperConfig) Validate() error {
errs = append(errs, field.Invalid(field.NewPath("openmcpOperator.config"), string(c.OpenMCPOperator.Config), "openmcp operator config is not valid yaml"))
}

for i, cp := range c.Providers.ClusterProviders {
if len(cp.Name) == 0 {
errs = append(errs, field.Required(field.NewPath("providers.clusterProviders").Index(i).Child("name"), "cluster provider name is required"))
}

if cp.Config != nil {
err := yaml.Unmarshal(cp.Config, &c.Providers.ClusterProviders[i].ConfigParsed)
if err != nil {
errs = append(errs, field.Invalid(field.NewPath("providers.clusterProviders").Index(i).Child("config"), string(cp.Config), "cluster provider config is not valid yaml"))
}
}
}

for i, sp := range c.Providers.ServiceProviders {
if len(sp.Name) == 0 {
errs = append(errs, field.Required(field.NewPath("providers.serviceProviders").Index(i).Child("name"), "service provider name is required"))
}

if sp.Config != nil {
err := yaml.Unmarshal(sp.Config, &c.Providers.ServiceProviders[i].ConfigParsed)
if err != nil {
errs = append(errs, field.Invalid(field.NewPath("providers.serviceProviders").Index(i).Child("config"), string(sp.Config), "service provider config is not valid yaml"))
}
}
}

for i, ps := range c.Providers.PlatformServices {
if len(ps.Name) == 0 {
errs = append(errs, field.Required(field.NewPath("providers.platformServices").Index(i).Child("name"), "platform service name is required"))
}

if ps.Config != nil {
err := yaml.Unmarshal(ps.Config, &c.Providers.PlatformServices[i].ConfigParsed)
if err != nil {
errs = append(errs, field.Invalid(field.NewPath("providers.platformServices").Index(i).Child("config"), string(ps.Config), "platform service config is not valid yaml"))
}
}
}

return errs.ToAggregate()
}
12 changes: 6 additions & 6 deletions internal/deployment-repo/deploymentRepoManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ func (m *DeploymentRepoManager) ApplyCustomResourceDefinitions(ctx context.Conte
}

for _, clusterProvider := range m.Config.Providers.ClusterProviders {
clusterProviderCV, err := m.compGetter.GetReferencedComponentVersionRecursive(ctx, m.compGetter.RootComponentVersion(), "cluster-provider-"+clusterProvider)
clusterProviderCV, err := m.compGetter.GetReferencedComponentVersionRecursive(ctx, m.compGetter.RootComponentVersion(), "cluster-provider-"+clusterProvider.Name)
if err != nil {
return fmt.Errorf("failed to get component version for cluster provider %s: %w", clusterProvider, err)
}
Expand All @@ -324,7 +324,7 @@ func (m *DeploymentRepoManager) ApplyCustomResourceDefinitions(ctx context.Conte
}

for _, serviceProvider := range m.Config.Providers.ServiceProviders {
serviceProviderCV, err := m.compGetter.GetReferencedComponentVersionRecursive(ctx, m.compGetter.RootComponentVersion(), "service-provider-"+serviceProvider)
serviceProviderCV, err := m.compGetter.GetReferencedComponentVersionRecursive(ctx, m.compGetter.RootComponentVersion(), "service-provider-"+serviceProvider.Name)
if err != nil {
return fmt.Errorf("failed to get component version for service provider %s: %w", serviceProvider, err)
}
Expand All @@ -335,7 +335,7 @@ func (m *DeploymentRepoManager) ApplyCustomResourceDefinitions(ctx context.Conte
}

for _, platformService := range m.Config.Providers.PlatformServices {
platformServiceCV, err := m.compGetter.GetReferencedComponentVersionRecursive(ctx, m.compGetter.RootComponentVersion(), "platform-service-"+platformService)
platformServiceCV, err := m.compGetter.GetReferencedComponentVersionRecursive(ctx, m.compGetter.RootComponentVersion(), "platform-service-"+platformService.Name)
if err != nil {
return fmt.Errorf("failed to get component version for platform service %s: %w", platformService, err)
}
Expand Down Expand Up @@ -496,15 +496,15 @@ func (m *DeploymentRepoManager) UpdateResourcesKustomization() error {
}

for _, clusterProvider := range m.Config.Providers.ClusterProviders {
files = append(files, filepath.Join("cluster-providers", clusterProvider+".yaml"))
files = append(files, filepath.Join("cluster-providers", clusterProvider.Name+".yaml"))
}

for _, serviceProvider := range m.Config.Providers.ServiceProviders {
files = append(files, filepath.Join("service-providers", serviceProvider+".yaml"))
files = append(files, filepath.Join("service-providers", serviceProvider.Name+".yaml"))
}

for _, platformService := range m.Config.Providers.PlatformServices {
files = append(files, filepath.Join("platform-services", platformService+".yaml"))
files = append(files, filepath.Join("platform-services", platformService.Name+".yaml"))
}

for _, manifest := range m.extraManifests {
Expand Down
19 changes: 16 additions & 3 deletions internal/deployment-repo/deploymentRepoManager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,22 @@ func TestDeploymentRepoManager(t *testing.T) {
Config: json.RawMessage(`{"someKey": "someValue"}`),
},
Providers: config.Providers{
ClusterProviders: []string{"test"},
ServiceProviders: []string{"test"},
PlatformServices: []string{"test"},
ClusterProviders: []config.Provider{
{
Name: "test",
Config: json.RawMessage(`{"verbosity": "info"}`),
},
},
ServiceProviders: []config.Provider{
{
Name: "test",
},
},
PlatformServices: []config.Provider{
{
Name: "test",
},
},
},
ImagePullSecrets: []string{"imgpull-a", "imgpull-b"},
}
Expand Down
22 changes: 15 additions & 7 deletions internal/deployment-repo/templater.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"github.com/go-git/go-billy/v5"
"github.com/go-git/go-git/v5"

"github.com/openmcp-project/bootstrapper/internal/config"

"github.com/openmcp-project/bootstrapper/internal/log"
ocmcli "github.com/openmcp-project/bootstrapper/internal/ocm-cli"
"github.com/openmcp-project/bootstrapper/internal/template"
Expand Down Expand Up @@ -119,10 +121,11 @@ type ProviderOptions struct {
Name string
Image string
ImagePullSecrets []string
Config map[string]interface{}
}

// TemplateProviders templates the specified cluster providers, service providers, and platform services
func TemplateProviders(ctx context.Context, clusterProviders, serviceProviders, platformServices, imagePullSecrets []string, ocmGetter *ocmcli.ComponentGetter, repo *git.Repository) error {
func TemplateProviders(ctx context.Context, clusterProviders, serviceProviders, platformServices []config.Provider, imagePullSecrets []string, ocmGetter *ocmcli.ComponentGetter, repo *git.Repository) error {
basePath := filepath.Join("resources", "openmcp")
clusterProvidersDir := filepath.Join(basePath, "cluster-providers")
serviceProvidersDir := filepath.Join(basePath, "service-providers")
Expand Down Expand Up @@ -150,7 +153,7 @@ func TemplateProviders(ctx context.Context, clusterProviders, serviceProviders,
}

for _, cp := range clusterProviders {
componentVersion, err := ocmGetter.GetReferencedComponentVersionRecursive(ctx, ocmGetter.RootComponentVersion(), "cluster-provider-"+cp)
componentVersion, err := ocmGetter.GetReferencedComponentVersionRecursive(ctx, ocmGetter.RootComponentVersion(), "cluster-provider-"+cp.Name)
if err != nil {
return fmt.Errorf("failed to get component version for cluster provider %s: %w", cp, err)
}
Expand All @@ -161,9 +164,10 @@ func TemplateProviders(ctx context.Context, clusterProviders, serviceProviders,
}

opts := &ProviderOptions{
Name: cp,
Name: cp.Name,
Image: *imageResource.Access.ImageReference,
ImagePullSecrets: imagePullSecrets,
Config: cp.ConfigParsed,
}

err = templateProvider(opts, clusterProviderTemplate, clusterProvidersDir, repo)
Expand All @@ -173,7 +177,7 @@ func TemplateProviders(ctx context.Context, clusterProviders, serviceProviders,
}

for _, sp := range serviceProviders {
componentVersion, err := ocmGetter.GetReferencedComponentVersionRecursive(ctx, ocmGetter.RootComponentVersion(), "service-provider-"+sp)
componentVersion, err := ocmGetter.GetReferencedComponentVersionRecursive(ctx, ocmGetter.RootComponentVersion(), "service-provider-"+sp.Name)
if err != nil {
return fmt.Errorf("failed to get component version for service provider %s: %w", sp, err)
}
Expand All @@ -184,9 +188,10 @@ func TemplateProviders(ctx context.Context, clusterProviders, serviceProviders,
}

opts := &ProviderOptions{
Name: sp,
Name: sp.Name,
Image: *imageResource.Access.ImageReference,
ImagePullSecrets: imagePullSecrets,
Config: sp.ConfigParsed,
}

err = templateProvider(opts, serviceProviderTemplate, serviceProvidersDir, repo)
Expand All @@ -196,7 +201,7 @@ func TemplateProviders(ctx context.Context, clusterProviders, serviceProviders,
}

for _, ps := range platformServices {
componentVersion, err := ocmGetter.GetReferencedComponentVersionRecursive(ctx, ocmGetter.RootComponentVersion(), "platform-service-"+ps)
componentVersion, err := ocmGetter.GetReferencedComponentVersionRecursive(ctx, ocmGetter.RootComponentVersion(), "platform-service-"+ps.Name)
if err != nil {
return fmt.Errorf("failed to get component version for platform service %s: %w", ps, err)
}
Expand All @@ -207,9 +212,10 @@ func TemplateProviders(ctx context.Context, clusterProviders, serviceProviders,
}

opts := &ProviderOptions{
Name: ps,
Name: ps.Name,
Image: *imageResource.Access.ImageReference,
ImagePullSecrets: imagePullSecrets,
Config: ps.ConfigParsed,
}

err = templateProvider(opts, platformServiceTemplate, platformServicesDir, repo)
Expand Down Expand Up @@ -238,13 +244,15 @@ func templateProvider(options *ProviderOptions, templateSource, dir string, repo
logger.Debugf("Creating provider %s with image %s in path %s", options.Name, options.Image, providerPath)

te := template.NewTemplateExecution()

templateInput := map[string]interface{}{
"values": map[string]interface{}{
"name": options.Name,
"image": map[string]interface{}{
"location": options.Image,
"imagePullSecrets": options.ImagePullSecrets,
},
"config": options.Config,
},
}

Expand Down
10 changes: 2 additions & 8 deletions internal/deployment-repo/templates/clusterProvider.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ spec:
- name: "{{ $value }}"
{{- end }}
{{- end }}
{{- if dig "env" "" .values }}
env:
{{- range $key, $value := .values.env }}
{{ $key }}: {{ $value }}
{{- end }}
{{- end }}
{{- if dig "verbosity" "" .values }}
verbosity: {{ .values.verbosity }}
{{- if dig "config" "" .values }}
{{ toYaml .values.config | indent 2 }}
{{- end }}
10 changes: 2 additions & 8 deletions internal/deployment-repo/templates/platformService.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ spec:
- name: "{{ $value }}"
{{- end }}
{{- end }}
{{- if dig "env" "" .values }}
env:
{{- range $key, $value := .values.env }}
{{ $key }}: {{ $value }}
{{- end }}
{{- end }}
{{- if dig "verbosity" "" .values }}
verbosity: {{ .values.verbosity }}
{{- if dig "config" "" .values }}
{{ toYaml .values.config | indent 2 }}
{{- end }}
10 changes: 2 additions & 8 deletions internal/deployment-repo/templates/serviceProvider.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ spec:
- name: "{{ $value }}"
{{- end }}
{{- end }}
{{- if dig "env" "" .values }}
env:
{{- range $key, $value := .values.env }}
{{ $key }}: {{ $value }}
{{- end }}
{{- end }}
{{- if dig "verbosity" "" .values }}
verbosity: {{ .values.verbosity }}
{{- if dig "config" "" .values }}
{{ toYaml .values.config | indent 2 }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ spec:
imagePullSecrets:
- name: "imgpull-a"
- name: "imgpull-b"
verbosity: info
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
patches:
- patch: |
apiVersion: apps/v1
kind: Deployment
metadata:
name: this_value_is_ignored
spec:
template:
spec:
imagePullSecrets:
- name: imgpull-a
- name: imgpull-b
target:
kind: Deployment
resources:
- rbac.yaml
- namespace.yaml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,19 @@ resources:
- rbac.yaml
- namespace.yaml
- deployment.yaml

{{- if .Values.imagePullSecrets }}
patches:
- target:
kind: Deployment
patch: |
apiVersion: apps/v1
kind: Deployment
metadata:
name: this_value_is_ignored
spec:
template:
spec:
imagePullSecrets:
{{ toYaml .Values.imagePullSecrets | indent 14 }}
{{- end }}