Skip to content

Commit

Permalink
Merge pull request #58 from uselagoon/minor-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
shreddedbacon authored Jul 8, 2022
2 parents f86a623 + ea944a9 commit 203cbc2
Show file tree
Hide file tree
Showing 17 changed files with 247 additions and 222 deletions.
4 changes: 2 additions & 2 deletions cmd/template_autogen_ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/spf13/cobra"
generator "github.com/uselagoon/build-deploy-tool/internal/generator"
"github.com/uselagoon/build-deploy-tool/internal/helpers"
routeTemplater "github.com/uselagoon/build-deploy-tool/internal/templating/routes"
ingresstemplate "github.com/uselagoon/build-deploy-tool/internal/templating/ingress"
)

var autogenRouteGeneration = &cobra.Command{
Expand Down Expand Up @@ -60,7 +60,7 @@ func AutogeneratedIngressGeneration(debug bool) error {
if debug {
fmt.Println(fmt.Sprintf("Templating autogenerated ingress manifest for %s to %s", route.Domain, fmt.Sprintf("%s/%s.yaml", savedTemplates, route.IngressName)))
}
templateYAML, err := routeTemplater.GenerateIngressTemplate(route, *lagoonBuild.BuildValues)
templateYAML, err := ingresstemplate.GenerateIngressTemplate(route, *lagoonBuild.BuildValues)
if err != nil {
return fmt.Errorf("couldn't generate template: %v", err)
}
Expand Down
10 changes: 5 additions & 5 deletions cmd/template_backups.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import (
"github.com/spf13/cobra"
generator "github.com/uselagoon/build-deploy-tool/internal/generator"
"github.com/uselagoon/build-deploy-tool/internal/helpers"
backupTemplater "github.com/uselagoon/build-deploy-tool/internal/templating/backups"
backuptemplate "github.com/uselagoon/build-deploy-tool/internal/templating/backups"
)

var backupGeneration = &cobra.Command{
Use: "backup",
Aliases: []string{"b"},
Short: "Generate the ingress templates for a Lagoon build",
Use: "backup-schedule",
Aliases: []string{"schedule", "bs"},
Short: "Generate the backup schedule templates for a Lagoon build",
RunE: func(cmd *cobra.Command, args []string) error {
return BackupTemplateGeneration(true)
},
Expand Down Expand Up @@ -55,7 +55,7 @@ func BackupTemplateGeneration(debug bool,
return err
}

templateYAML, err := backupTemplater.GenerateBackupSchedule(*lagoonBuild.BuildValues)
templateYAML, err := backuptemplate.GenerateBackupSchedule(*lagoonBuild.BuildValues)
if err != nil {
return fmt.Errorf("couldn't generate template: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/template_dbaas.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (

var dbaasGeneration = &cobra.Command{
Use: "dbaas",
Aliases: []string{"b"},
Short: "Generate the ingress templates for a Lagoon build",
Aliases: []string{"db"},
Short: "Generate the DBaaS templates for a Lagoon build",
RunE: func(cmd *cobra.Command, args []string) error {
return DBaaSTemplateGeneration(true)
},
Expand Down
6 changes: 3 additions & 3 deletions cmd/template_ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/spf13/cobra"
generator "github.com/uselagoon/build-deploy-tool/internal/generator"
"github.com/uselagoon/build-deploy-tool/internal/helpers"
routeTemplater "github.com/uselagoon/build-deploy-tool/internal/templating/routes"
ingresstemplate "github.com/uselagoon/build-deploy-tool/internal/templating/ingress"
)

var routeGeneration = &cobra.Command{
Expand Down Expand Up @@ -59,7 +59,7 @@ func IngressTemplateGeneration(debug bool) error {
if debug {
fmt.Println(fmt.Sprintf("Templating ingress manifest for %s to %s", route.Domain, fmt.Sprintf("%s/%s.yaml", savedTemplates, route.Domain)))
}
templateYAML, err := routeTemplater.GenerateIngressTemplate(route, *lagoonBuild.BuildValues)
templateYAML, err := ingresstemplate.GenerateIngressTemplate(route, *lagoonBuild.BuildValues)
if err != nil {
return fmt.Errorf("couldn't generate template: %v", err)
}
Expand All @@ -75,7 +75,7 @@ func IngressTemplateGeneration(debug bool) error {
if debug {
fmt.Println(fmt.Sprintf("Templating active/standby ingress manifest for %s to %s", route.Domain, fmt.Sprintf("%s/%s.yaml", savedTemplates, route.Domain)))
}
templateYAML, err := routeTemplater.GenerateIngressTemplate(route, *lagoonBuild.BuildValues)
templateYAML, err := ingresstemplate.GenerateIngressTemplate(route, *lagoonBuild.BuildValues)
if err != nil {
return fmt.Errorf("couldn't generate template: %v", err)
}
Expand Down
58 changes: 29 additions & 29 deletions internal/generator/backups.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const (
)

func generateBackupValues(
lagoonValues *BuildValues,
buildValues *BuildValues,
lYAML *lagoon.YAML,
mergedVariables []lagoon.EnvironmentVariable,
debug bool,
Expand All @@ -28,9 +28,9 @@ func generateBackupValues(
// create a new schedule placeholder set to the default value so it can be adjusted through this
// generator
newBackupSchedule := defaultBackupSchedule
switch lagoonValues.BuildType {
switch buildValues.BuildType {
case "branch":
if lagoonValues.EnvironmentType == "development" {
if buildValues.EnvironmentType == "development" {
lagoonBackupDevSchedule, _ := lagoon.GetLagoonVariable("LAGOON_BACKUP_DEV_SCHEDULE", []string{"build", "global"}, mergedVariables)
devBackupSchedule := ""
if lagoonBackupDevSchedule != nil {
Expand Down Expand Up @@ -61,86 +61,86 @@ func generateBackupValues(
newBackupSchedule = prBackupSchedule
}
}
lagoonValues.Backup.BackupSchedule, err = helpers.ConvertCrontab(lagoonValues.Namespace, newBackupSchedule)
buildValues.Backup.BackupSchedule, err = helpers.ConvertCrontab(buildValues.Namespace, newBackupSchedule)
if err != nil {
return fmt.Errorf("Unable to convert crontab for default backup schedule: %v", err)
}
flagCheckSchedule := helpers.GetEnv("K8UP_WEEKLY_RANDOM_FEATURE_FLAG", defaultCheckSchedule, debug)
if flagCheckSchedule == "enabled" {
lagoonValues.Backup.CheckSchedule = "@weekly-random"
buildValues.Backup.CheckSchedule = "@weekly-random"
} else {
lagoonValues.Backup.CheckSchedule, err = helpers.ConvertCrontab(lagoonValues.Namespace, flagCheckSchedule)
buildValues.Backup.CheckSchedule, err = helpers.ConvertCrontab(buildValues.Namespace, flagCheckSchedule)
if err != nil {
return fmt.Errorf("Unable to convert crontab for default check schedule: %v", err)
}
}
flagPruneSchedule := helpers.GetEnv("K8UP_WEEKLY_RANDOM_FEATURE_FLAG", defaultPruneSchedule, debug)
if flagPruneSchedule == "enabled" {
lagoonValues.Backup.PruneSchedule = "@weekly-random"
buildValues.Backup.PruneSchedule = "@weekly-random"
} else {
lagoonValues.Backup.PruneSchedule, err = helpers.ConvertCrontab(lagoonValues.Namespace, flagPruneSchedule)
buildValues.Backup.PruneSchedule, err = helpers.ConvertCrontab(buildValues.Namespace, flagPruneSchedule)
if err != nil {
return fmt.Errorf("Unable to convert crontab for default prune schedule: %v", err)
}
}

lagoonValues.Backup.PruneRetention.Hourly, err = helpers.EGetEnvInt("HOURLY_BACKUP_DEFAULT_RETENTION", hourlyDefaultBackupRetention, debug)
buildValues.Backup.PruneRetention.Hourly, err = helpers.EGetEnvInt("HOURLY_BACKUP_DEFAULT_RETENTION", hourlyDefaultBackupRetention, debug)
if err != nil {
return fmt.Errorf("Unable to convert hourly retention provided in the environment variable to integer")
}
lagoonValues.Backup.PruneRetention.Daily, err = helpers.EGetEnvInt("DAILY_BACKUP_DEFAULT_RETENTION", dailyDefaultBackupRetention, debug)
buildValues.Backup.PruneRetention.Daily, err = helpers.EGetEnvInt("DAILY_BACKUP_DEFAULT_RETENTION", dailyDefaultBackupRetention, debug)
if err != nil {
return fmt.Errorf("Unable to convert daily retention provided in the environment variable to integer")
}
lagoonValues.Backup.PruneRetention.Weekly, err = helpers.EGetEnvInt("WEEKLY_BACKUP_DEFAULT_RETENTION", weeklyDefaultBackupRetention, debug)
buildValues.Backup.PruneRetention.Weekly, err = helpers.EGetEnvInt("WEEKLY_BACKUP_DEFAULT_RETENTION", weeklyDefaultBackupRetention, debug)
if err != nil {
return fmt.Errorf("Unable to convert weekly retention provided in the environment variable to integer")
}
lagoonValues.Backup.PruneRetention.Monthly, err = helpers.EGetEnvInt("MONTHLY_BACKUP_DEFAULT_RETENTION", monthlyDefaultBackupRetention, debug)
buildValues.Backup.PruneRetention.Monthly, err = helpers.EGetEnvInt("MONTHLY_BACKUP_DEFAULT_RETENTION", monthlyDefaultBackupRetention, debug)
if err != nil {
return fmt.Errorf("Unable to convert monthly retention provided in the environment variable to integer")
}

if lYAML.BackupRetention.Production.Hourly != nil && lagoonValues.EnvironmentType == "production" {
lagoonValues.Backup.PruneRetention.Hourly = *lYAML.BackupRetention.Production.Hourly
if lYAML.BackupRetention.Production.Hourly != nil && buildValues.EnvironmentType == "production" {
buildValues.Backup.PruneRetention.Hourly = *lYAML.BackupRetention.Production.Hourly
}
if lYAML.BackupRetention.Production.Daily != nil && lagoonValues.EnvironmentType == "production" {
lagoonValues.Backup.PruneRetention.Daily = *lYAML.BackupRetention.Production.Daily
if lYAML.BackupRetention.Production.Daily != nil && buildValues.EnvironmentType == "production" {
buildValues.Backup.PruneRetention.Daily = *lYAML.BackupRetention.Production.Daily
}
if lYAML.BackupRetention.Production.Weekly != nil && lagoonValues.EnvironmentType == "production" {
lagoonValues.Backup.PruneRetention.Weekly = *lYAML.BackupRetention.Production.Weekly
if lYAML.BackupRetention.Production.Weekly != nil && buildValues.EnvironmentType == "production" {
buildValues.Backup.PruneRetention.Weekly = *lYAML.BackupRetention.Production.Weekly
}
if lYAML.BackupRetention.Production.Monthly != nil && lagoonValues.EnvironmentType == "production" {
lagoonValues.Backup.PruneRetention.Monthly = *lYAML.BackupRetention.Production.Monthly
if lYAML.BackupRetention.Production.Monthly != nil && buildValues.EnvironmentType == "production" {
buildValues.Backup.PruneRetention.Monthly = *lYAML.BackupRetention.Production.Monthly
}
if lYAML.BackupSchedule.Production != "" && lagoonValues.EnvironmentType == "production" {
lagoonValues.Backup.BackupSchedule, err = helpers.ConvertCrontab(lagoonValues.Namespace, lYAML.BackupSchedule.Production)
if lYAML.BackupSchedule.Production != "" && buildValues.EnvironmentType == "production" {
buildValues.Backup.BackupSchedule, err = helpers.ConvertCrontab(buildValues.Namespace, lYAML.BackupSchedule.Production)
if err != nil {
return fmt.Errorf("Unable to convert crontab for default backup schedule from .lagoon.yml: %v", err)
}
}
// check for custom baas backup variables
lagoonBaaSCustomBackupEndpoint, _ := lagoon.GetLagoonVariable("LAGOON_BAAS_CUSTOM_BACKUP_ENDPOINT", []string{"build", "global"}, mergedVariables)
if lagoonBaaSCustomBackupEndpoint != nil {
lagoonValues.Backup.S3Endpoint = lagoonBaaSCustomBackupEndpoint.Value
buildValues.Backup.S3Endpoint = lagoonBaaSCustomBackupEndpoint.Value
}
lagoonBaaSCustomBackupBucket, _ := lagoon.GetLagoonVariable("LAGOON_BAAS_CUSTOM_BACKUP_BUCKET", []string{"build", "global"}, mergedVariables)
if lagoonBaaSCustomBackupBucket != nil {
lagoonValues.Backup.S3BucketName = lagoonBaaSCustomBackupBucket.Value
buildValues.Backup.S3BucketName = lagoonBaaSCustomBackupBucket.Value
}
lagoonBaaSCustomBackupAccessKey, _ := lagoon.GetLagoonVariable("LAGOON_BAAS_CUSTOM_BACKUP_ACCESS_KEY", []string{"build", "global"}, mergedVariables)
lagoonBaaSCustomBackupSecretKey, _ := lagoon.GetLagoonVariable("LAGOON_BAAS_CUSTOM_BACKUP_SECRET_KEY", []string{"build", "global"}, mergedVariables)
if lagoonBaaSCustomBackupAccessKey != nil && lagoonBaaSCustomBackupSecretKey != nil {
lagoonValues.Backup.CustomLocation.BackupLocationAccessKey = lagoonBaaSCustomBackupAccessKey.Value
lagoonValues.Backup.CustomLocation.BackupLocationSecretKey = lagoonBaaSCustomBackupSecretKey.Value
lagoonValues.Backup.S3SecretName = "lagoon-baas-custom-backup-credentials"
buildValues.Backup.CustomLocation.BackupLocationAccessKey = lagoonBaaSCustomBackupAccessKey.Value
buildValues.Backup.CustomLocation.BackupLocationSecretKey = lagoonBaaSCustomBackupSecretKey.Value
buildValues.Backup.S3SecretName = "lagoon-baas-custom-backup-credentials"
}
// check for custom baas restore variables
lagoonBaaSCustomRestoreAccessKey, _ := lagoon.GetLagoonVariable("LAGOON_BAAS_CUSTOM_RESTORE_ACCESS_KEY", []string{"build", "global"}, mergedVariables)
lagoonBaaSCustomRestoreSecretKey, _ := lagoon.GetLagoonVariable("LAGOON_BAAS_CUSTOM_RESTORE_SECRET_KEY", []string{"build", "global"}, mergedVariables)
if lagoonBaaSCustomRestoreAccessKey != nil && lagoonBaaSCustomRestoreSecretKey != nil {
lagoonValues.Backup.CustomLocation.RestoreLocationAccessKey = lagoonBaaSCustomRestoreAccessKey.Value
lagoonValues.Backup.CustomLocation.RestoreLocationSecretKey = lagoonBaaSCustomRestoreSecretKey.Value
buildValues.Backup.CustomLocation.RestoreLocationAccessKey = lagoonBaaSCustomRestoreAccessKey.Value
buildValues.Backup.CustomLocation.RestoreLocationSecretKey = lagoonBaaSCustomRestoreSecretKey.Value
}
return nil
}
30 changes: 15 additions & 15 deletions internal/generator/backups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

func Test_generateBackupValues(t *testing.T) {
type args struct {
lagoonValues *BuildValues
buildValues *BuildValues
lYAML *lagoon.YAML
mergedVariables []lagoon.EnvironmentVariable
debug bool
Expand All @@ -27,7 +27,7 @@ func Test_generateBackupValues(t *testing.T) {
{
name: "test1",
args: args{
lagoonValues: &BuildValues{
buildValues: &BuildValues{
BuildType: "branch",
EnvironmentType: "development",
Namespace: "example-com-main",
Expand Down Expand Up @@ -55,7 +55,7 @@ func Test_generateBackupValues(t *testing.T) {
{
name: "test2 - dev schedule from lagoon api variable",
args: args{
lagoonValues: &BuildValues{
buildValues: &BuildValues{
BuildType: "branch",
EnvironmentType: "development",
Namespace: "example-com-main",
Expand Down Expand Up @@ -85,7 +85,7 @@ func Test_generateBackupValues(t *testing.T) {
{
name: "test3 - dev schedule from build pod variable",
args: args{
lagoonValues: &BuildValues{
buildValues: &BuildValues{
BuildType: "branch",
EnvironmentType: "development",
Namespace: "example-com-main",
Expand Down Expand Up @@ -116,7 +116,7 @@ func Test_generateBackupValues(t *testing.T) {
{
name: "test4- pr schedule from lagoon api variable",
args: args{
lagoonValues: &BuildValues{
buildValues: &BuildValues{
BuildType: "pullrequest",
EnvironmentType: "development",
Namespace: "example-com-main",
Expand Down Expand Up @@ -146,7 +146,7 @@ func Test_generateBackupValues(t *testing.T) {
{
name: "test5 - pr schedule from build pod variable",
args: args{
lagoonValues: &BuildValues{
buildValues: &BuildValues{
BuildType: "pullrequest",
EnvironmentType: "development",
Namespace: "example-com-main",
Expand Down Expand Up @@ -177,7 +177,7 @@ func Test_generateBackupValues(t *testing.T) {
{
name: "test6 - pr env with dev schedule from lagoon api variable",
args: args{
lagoonValues: &BuildValues{
buildValues: &BuildValues{
BuildType: "pullrequest",
EnvironmentType: "development",
Namespace: "example-com-main",
Expand Down Expand Up @@ -207,7 +207,7 @@ func Test_generateBackupValues(t *testing.T) {
{
name: "test7 - pr env with dev schedule from build pod variable",
args: args{
lagoonValues: &BuildValues{
buildValues: &BuildValues{
BuildType: "pullrequest",
EnvironmentType: "development",
Namespace: "example-com-main",
Expand Down Expand Up @@ -238,7 +238,7 @@ func Test_generateBackupValues(t *testing.T) {
{
name: "test8 - production with lagoon yaml overrides",
args: args{
lagoonValues: &BuildValues{
buildValues: &BuildValues{
BuildType: "branch",
EnvironmentType: "production",
Namespace: "example-com-main",
Expand Down Expand Up @@ -278,7 +278,7 @@ func Test_generateBackupValues(t *testing.T) {
{
name: "test9 - custom backup configuration",
args: args{
lagoonValues: &BuildValues{
buildValues: &BuildValues{
BuildType: "branch",
EnvironmentType: "development",
Namespace: "example-com-main",
Expand Down Expand Up @@ -314,7 +314,7 @@ func Test_generateBackupValues(t *testing.T) {
{
name: "test10 - custom backup configuration with endpoint and bucket",
args: args{
lagoonValues: &BuildValues{
buildValues: &BuildValues{
BuildType: "branch",
EnvironmentType: "development",
Namespace: "example-com-main",
Expand Down Expand Up @@ -354,7 +354,7 @@ func Test_generateBackupValues(t *testing.T) {
{
name: "test11 - custom restore configuration",
args: args{
lagoonValues: &BuildValues{
buildValues: &BuildValues{
BuildType: "branch",
EnvironmentType: "development",
Namespace: "example-com-main",
Expand Down Expand Up @@ -389,7 +389,7 @@ func Test_generateBackupValues(t *testing.T) {
{
name: "test11 - custom restore and backup configuration with endpoint and bucket",
args: args{
lagoonValues: &BuildValues{
buildValues: &BuildValues{
BuildType: "branch",
EnvironmentType: "development",
Namespace: "example-com-main",
Expand Down Expand Up @@ -439,10 +439,10 @@ func Test_generateBackupValues(t *testing.T) {
t.Errorf("%v", err)
}
}
if err := generateBackupValues(tt.args.lagoonValues, tt.args.lYAML, tt.args.mergedVariables, tt.args.debug); (err != nil) != tt.wantErr {
if err := generateBackupValues(tt.args.buildValues, tt.args.lYAML, tt.args.mergedVariables, tt.args.debug); (err != nil) != tt.wantErr {
t.Errorf("generateBackupValues() error = %v, wantErr %v", err, tt.wantErr)
}
lValues, _ := json.Marshal(tt.args.lagoonValues)
lValues, _ := json.Marshal(tt.args.buildValues)
wValues, _ := json.Marshal(tt.want)
if !reflect.DeepEqual(string(lValues), string(wValues)) {
t.Errorf("GenerateBackupSchedule() = %v, want %v", string(lValues), string(wValues))
Expand Down
24 changes: 13 additions & 11 deletions internal/generator/buildvalues.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@ import "github.com/uselagoon/build-deploy-tool/internal/lagoon"

// BuildValues is the values file data generated by the lagoon build
type BuildValues struct {
Project string `json:"project"`
Environment string `json:"environment"`
EnvironmentType string `json:"environmentType"`
Namespace string `json:"namespace"`
GitSha string `json:"gitSha"`
BuildType string `json:"buildType"`
Kubernetes string `json:"kubernetes"`
LagoonVersion string `json:"lagoonVersion"`
ActiveEnvironment string `json:"activeEnvironment"`
StandbyEnvironment string `json:"standbyEnvironment"`
PodSecurityContext struct {
Project string `json:"project"`
Environment string `json:"environment"`
EnvironmentType string `json:"environmentType"`
Namespace string `json:"namespace"`
GitSha string `json:"gitSha"`
BuildType string `json:"buildType"`
Kubernetes string `json:"kubernetes"`
LagoonVersion string `json:"lagoonVersion"`
ActiveEnvironment string `json:"activeEnvironment"`
StandbyEnvironment string `json:"standbyEnvironment"`
IsActiveEnvironment bool `json:"isActiveEnvironment"`
IsStandbyEnvironment bool `json:"isStandbyEnvironment"`
PodSecurityContext struct {
FsGroup int `json:"fsGroup"`
RunAsGroup int `json:"runAsGroup"`
RunAsUser int `json:"runAsUser"`
Expand Down
Loading

0 comments on commit 203cbc2

Please sign in to comment.