65 lines
1.3 KiB
Go
65 lines
1.3 KiB
Go
package kustomize
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"git.badhouseplants.net/allanger/shoebill/internal/utils/githelper"
|
|
kustomize_types "sigs.k8s.io/kustomize/api/types"
|
|
"sigs.k8s.io/yaml"
|
|
)
|
|
|
|
type Kusmtomize struct {
|
|
Files []string
|
|
}
|
|
|
|
func (k *Kusmtomize) PopulateResources(path string) error {
|
|
files, err := os.ReadDir(fmt.Sprintf("%s/src", path))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for _, file := range files {
|
|
if file.Name() != ".gitkeep" {
|
|
k.Files = append(k.Files, fmt.Sprintf("src/%s", file.Name()))
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func Generate(path string, gh githelper.Githelper) error {
|
|
kustomize := &Kusmtomize{}
|
|
if err := kustomize.PopulateResources(path); err != nil {
|
|
return err
|
|
}
|
|
|
|
kustomization := kustomize_types.Kustomization{
|
|
TypeMeta: kustomize_types.TypeMeta{
|
|
Kind: kustomize_types.KustomizationKind,
|
|
APIVersion: kustomize_types.ComponentVersion,
|
|
},
|
|
MetaData: &kustomize_types.ObjectMeta{
|
|
Name: "helm-root",
|
|
Namespace: "flux-system",
|
|
},
|
|
Resources: kustomize.Files,
|
|
}
|
|
manifest, err := yaml.Marshal(kustomization)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
file, err := os.Create(path + "/kustomization.yaml")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if _, err := file.Write(manifest); err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := gh.AddAllAndCommit(path, "Update the root kustomization"); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|