Skip to content

Commit

Permalink
Template with kustomize in LoadManifests
Browse files Browse the repository at this point in the history
Signed-off-by: Shinnosuke Sawada-Dazai <shin@warashi.dev>
  • Loading branch information
Warashi committed Oct 24, 2024
1 parent 061721f commit 07ad220
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions pkg/app/pipedv1/plugin/kubernetes/provider/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package provider

import (
"context"
"errors"
"fmt"
"io/fs"
Expand All @@ -24,6 +25,7 @@ import (
"strconv"
"strings"

"go.uber.org/zap"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"sigs.k8s.io/yaml"

Expand All @@ -39,20 +41,30 @@ const (
)

type LoaderInput struct {
AppName string
AppDir string
ConfigFilename string
Manifests []string

Namespace string
TemplatingMethod TemplatingMethod

KustomizeVersion string
KustomizeOptions map[string]string

// TODO: define fields for LoaderInput.
}

type Loader struct {
toolRegistry ToolRegistry
}

type ToolRegistry interface {
Kustomize(ctx context.Context, version string) (string, error)
Helm(ctx context.Context, version string) (string, error)
}

func (l *Loader) LoadManifests(input LoaderInput) (manifests []Manifest, err error) {
func (l *Loader) LoadManifests(ctx context.Context, input LoaderInput) (manifests []Manifest, err error) {

Check warning on line 67 in pkg/app/pipedv1/plugin/kubernetes/provider/loader.go

View check run for this annotation

Codecov / codecov/patch

pkg/app/pipedv1/plugin/kubernetes/provider/loader.go#L67

Added line #L67 was not covered by tests
defer func() {
// Override namespace if set because ParseManifests does not parse it
// if namespace is not explicitly specified in the manifests.
Expand All @@ -64,7 +76,18 @@ func (l *Loader) LoadManifests(input LoaderInput) (manifests []Manifest, err err
case TemplatingMethodHelm:
return nil, errors.New("not implemented yet")
case TemplatingMethodKustomize:
return nil, errors.New("not implemented yet")
kustomizePath, err := l.toolRegistry.Kustomize(ctx, input.KustomizeVersion)
if err != nil {
return nil, fmt.Errorf("failed to get kustomize tool: %w", err)
}

Check warning on line 82 in pkg/app/pipedv1/plugin/kubernetes/provider/loader.go

View check run for this annotation

Codecov / codecov/patch

pkg/app/pipedv1/plugin/kubernetes/provider/loader.go#L79-L82

Added lines #L79 - L82 were not covered by tests

k := NewKustomize(kustomizePath, zap.NewNop()) // TODO: pass logger
data, err := k.Template(ctx, input.AppName, input.AppDir, input.KustomizeOptions)
if err != nil {
return nil, fmt.Errorf("failed to template kustomize manifests: %w", err)
}

Check warning on line 88 in pkg/app/pipedv1/plugin/kubernetes/provider/loader.go

View check run for this annotation

Codecov / codecov/patch

pkg/app/pipedv1/plugin/kubernetes/provider/loader.go#L84-L88

Added lines #L84 - L88 were not covered by tests

return ParseManifests(data)

Check warning on line 90 in pkg/app/pipedv1/plugin/kubernetes/provider/loader.go

View check run for this annotation

Codecov / codecov/patch

pkg/app/pipedv1/plugin/kubernetes/provider/loader.go#L90

Added line #L90 was not covered by tests
case TemplatingMethodNone:
return LoadPlainYAMLManifests(input.AppDir, input.Manifests, input.ConfigFilename)
default:
Expand Down

0 comments on commit 07ad220

Please sign in to comment.