Skip to content

Commit

Permalink
feat: initial work on resource workload support
Browse files Browse the repository at this point in the history
  • Loading branch information
shreddedbacon committed Nov 9, 2023
1 parent 63fdf16 commit 6a8b2e2
Show file tree
Hide file tree
Showing 39 changed files with 1,768 additions and 77 deletions.
7 changes: 3 additions & 4 deletions cmd/template_autogen_ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cmd
import (
"fmt"
"io/fs"
"io/ioutil"
"os"
"reflect"
"testing"
Expand Down Expand Up @@ -643,14 +642,14 @@ func TestAutogeneratedIngressGeneration(t *testing.T) {
t.Errorf("AutogeneratedIngressGeneration() error = %v, wantErr %v", err, tt.wantErr)
}

files, err := ioutil.ReadDir(savedTemplates)
files, err := os.ReadDir(savedTemplates)
if err != nil {
t.Errorf("couldn't read directory %v: %v", savedTemplates, err)
}
resultSize := 0
results := []fs.FileInfo{}
results := []fs.DirEntry{}
if !tt.emptyDir {
results, err = ioutil.ReadDir(tt.want)
results, err = os.ReadDir(tt.want)
if err != nil {
t.Errorf("couldn't read directory %v: %v", tt.want, err)
}
Expand Down
5 changes: 2 additions & 3 deletions cmd/template_backups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"fmt"
"io/ioutil"
"os"
"reflect"
"testing"
Expand Down Expand Up @@ -275,11 +274,11 @@ func TestBackupTemplateGeneration(t *testing.T) {
if err := BackupTemplateGeneration(generator); (err != nil) != tt.wantErr {
t.Errorf("BackupTemplateGeneration() error = %v, wantErr %v", err, tt.wantErr)
}
files, err := ioutil.ReadDir(savedTemplates)
files, err := os.ReadDir(savedTemplates)
if err != nil {
t.Errorf("couldn't read directory %v: %v", savedTemplates, err)
}
results, err := ioutil.ReadDir(tt.want)
results, err := os.ReadDir(tt.want)
if err != nil {
t.Errorf("couldn't read directory %v: %v", tt.want, err)
}
Expand Down
5 changes: 2 additions & 3 deletions cmd/template_dbaas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"fmt"
"io/ioutil"
"os"
"reflect"
"testing"
Expand Down Expand Up @@ -172,11 +171,11 @@ func TestDBaaSTemplateGeneration(t *testing.T) {
if err := DBaaSTemplateGeneration(generator); (err != nil) != tt.wantErr {
t.Errorf("DBaaSTemplateGeneration() error = %v, wantErr %v", err, tt.wantErr)
}
files, err := ioutil.ReadDir(savedTemplates)
files, err := os.ReadDir(savedTemplates)
if err != nil {
t.Errorf("couldn't read directory %v: %v", savedTemplates, err)
}
results, err := ioutil.ReadDir(tt.want)
results, err := os.ReadDir(tt.want)
if err != nil {
t.Errorf("couldn't read directory %v: %v", tt.want, err)
}
Expand Down
5 changes: 2 additions & 3 deletions cmd/template_ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"fmt"
"io/ioutil"
"os"
"reflect"
"testing"
Expand Down Expand Up @@ -568,11 +567,11 @@ func TestTemplateRoutes(t *testing.T) {
t.Errorf("%v", err)
}

files, err := ioutil.ReadDir(savedTemplates)
files, err := os.ReadDir(savedTemplates)
if err != nil {
t.Errorf("couldn't read directory %v: %v", savedTemplates, err)
}
results, err := ioutil.ReadDir(tt.want)
results, err := os.ReadDir(tt.want)
if err != nil {
t.Errorf("couldn't read directory %v: %v", tt.want, err)
}
Expand Down
58 changes: 58 additions & 0 deletions cmd/template_resourceworkloads.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package cmd

import (
"fmt"

"github.com/spf13/cobra"
generator "github.com/uselagoon/build-deploy-tool/internal/generator"
"github.com/uselagoon/build-deploy-tool/internal/helpers"
hpatemplate "github.com/uselagoon/build-deploy-tool/internal/templating/resources/hpa"
pdbtemplate "github.com/uselagoon/build-deploy-tool/internal/templating/resources/pdb"
)

var resourceWorkloadGeneration = &cobra.Command{
Use: "resource-workloads",
Aliases: []string{"rw"},
Short: "Generate the resource workload templates for a Lagoon build",
RunE: func(cmd *cobra.Command, args []string) error {
generator, err := generatorInput(true)
if err != nil {
return err
}
return ResourceWorkloadTemplateGeneration(generator)
},
}

// IngressTemplateGeneration .
func ResourceWorkloadTemplateGeneration(g generator.GeneratorInput) error {
lagoonBuild, err := generator.NewGenerator(
g,
)
if err != nil {
return err
}
savedTemplates := g.SavedTemplatesPath

// generate the templates
if g.Debug {
fmt.Println(fmt.Sprintf("Templating HPA manifests to %s", fmt.Sprintf("%s/%s.yaml", savedTemplates, "hpas")))
}
templateYAML, err := hpatemplate.GenerateHPATemplate(*lagoonBuild.BuildValues)
if err != nil {
return fmt.Errorf("couldn't generate template: %v", err)
}
helpers.WriteTemplateFile(fmt.Sprintf("%s/%s.yaml", savedTemplates, "hpas"), templateYAML)
if g.Debug {
fmt.Println(fmt.Sprintf("Templating HPA manifests to %s", fmt.Sprintf("%s/%s.yaml", savedTemplates, "pdbs")))
}
templateYAML, err = pdbtemplate.GeneratePDBTemplate(*lagoonBuild.BuildValues)
if err != nil {
return fmt.Errorf("couldn't generate template: %v", err)
}
helpers.WriteTemplateFile(fmt.Sprintf("%s/%s.yaml", savedTemplates, "pdbs"), templateYAML)
return nil
}

func init() {
templateCmd.AddCommand(resourceWorkloadGeneration)
}
Loading

0 comments on commit 6a8b2e2

Please sign in to comment.