Skip to content

Commit

Permalink
Replace argocd dirver by kubernetes driver
Browse files Browse the repository at this point in the history
  • Loading branch information
kajogo777 committed Nov 22, 2022
1 parent 1b6863d commit c421358
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
6 changes: 3 additions & 3 deletions internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ func Run(environment string, configDir string, stackPath string, buildersPath st
}
terraform.ApplyAll(stack)

argocd := drivers.ArgoCDDriver{
Path: path.Join("build", environment, "argocd"),
kubernetes := drivers.KubernetesDriver{
Path: path.Join("build", environment, "kubernetes"),
}
argocd.ApplyAll(stack)
kubernetes.ApplyAll(stack)

return nil
}
24 changes: 18 additions & 6 deletions internal/drivers/argocd.go → internal/drivers/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,24 @@ import (
"fmt"
"os"
"path"
"strings"

"cuelang.org/go/cue"
"cuelang.org/go/encoding/yaml"
"devopzilla.com/guku/internal/stack"
"devopzilla.com/guku/internal/utils"
)

type ArgoCDDriver struct {
type KubernetesDriver struct {
Path string
}

func (d *ArgoCDDriver) match(resource cue.Value) bool {
func (d *KubernetesDriver) match(resource cue.Value) bool {
driverName, _ := resource.LookupPath(cue.ParsePath("$metadata.labels.driver")).String()
return driverName == "argocd"
return driverName == "kubernetes"
}

func (d *ArgoCDDriver) ApplyAll(stack *stack.Stack) error {
func (d *KubernetesDriver) ApplyAll(stack *stack.Stack) error {
foundResources := false

for _, componentId := range stack.GetTasks() {
Expand All @@ -35,12 +36,23 @@ func (d *ArgoCDDriver) ApplyAll(stack *stack.Stack) error {
return err
}

kind := resource.LookupPath(cue.ParsePath("kind"))
if kind.Err() != nil {
return kind.Err()
}

kindString, err := kind.String()
if err != nil {
return err
}

data, err := yaml.Encode(resource)
if err != nil {
return err
}

resourceFilePath := path.Join(d.Path, componentId+"-"+resourceIter.Label()+".yml")
fileName := fmt.Sprintf("%s-%s-%s.yml", componentId, resourceIter.Label(), strings.ToLower(kindString))
resourceFilePath := path.Join(d.Path, fileName)
if _, err := os.Stat(d.Path); os.IsNotExist(err) {
os.MkdirAll(d.Path, 0700)
}
Expand All @@ -50,7 +62,7 @@ func (d *ArgoCDDriver) ApplyAll(stack *stack.Stack) error {
}

if foundResources {
fmt.Printf("[argocd] applied resources to \"%s/*.yml\"\n", d.Path)
fmt.Printf("[kubernetes] applied resources to \"%s/*.yml\"\n", d.Path)
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/guku.io/devx/v1/transformers/argocd/transformers.cue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

_#ArgoCDApplicationResource: {
$metadata: labels: driver: "argocd"
$metadata: labels: driver: "kubernetes"
argoapp.#Application
spec: project: string | *"default"
}
Expand Down

0 comments on commit c421358

Please sign in to comment.