Skip to content

Commit

Permalink
chore: merge branch 'main' into cleanup-removed-ingress
Browse files Browse the repository at this point in the history
  • Loading branch information
shreddedbacon committed Oct 18, 2023
2 parents 1a5ebff + 1882d5d commit fae5d53
Show file tree
Hide file tree
Showing 90 changed files with 3,515 additions and 1,193 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: "^1.17"
go-version: "^1.18"
- name: Set up environment
run: echo "GOVERSION=$(go version)" >> $GITHUB_ENV
- name: Run GoReleaser
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
matrix:
goversion:
- 1.17
- 1.18
steps:
-
name: Checkout PR
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lagoon-core-docker-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
matrix:
goversion:
- 1.17
- 1.18
steps:
-
name: Checkout Branch or Tag
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: "^1.17"
go-version: "^1.18"
- name: Install ccv
run: >
curl -sSL https://github.com/smlx/ccv/releases/download/v0.3.2/ccv_0.3.2_linux_amd64.tar.gz
Expand Down Expand Up @@ -49,7 +49,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: "^1.17"
go-version: "^1.18"
- name: Set up environment
run: echo "GOVERSION=$(go version)" >> $GITHUB_ENV
- name: Run GoReleaser
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tag-to-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: "^1.17"
go-version: "^1.18"
- name: Set up environment
run: echo "GOVERSION=$(go version)" >> $GITHUB_ENV
- name: Run GoReleaser
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: "^1.17"
go-version: "^1.18"
- name: Run Tests
run: go test -v ./...
4 changes: 1 addition & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ARG UPSTREAM_REPO
ARG UPSTREAM_TAG
ARG GO_VER
FROM ${UPSTREAM_REPO:-uselagoon}/commons:${UPSTREAM_TAG:-latest} as commons
FROM golang:${GO_VER:-1.17}-alpine3.16 as golang
FROM golang:${GO_VER:-1.18}-alpine as golang

RUN apk add --no-cache git
RUN go install github.com/a8m/envsubst/cmd/[email protected]
Expand Down Expand Up @@ -102,8 +102,6 @@ COPY legacy/scripts /kubectl-build-deploy/scripts

COPY legacy/helmcharts /kubectl-build-deploy/helmcharts

ENV IMAGECACHE_REGISTRY=imagecache.amazeeio.cloud

ENV DBAAS_OPERATOR_HTTP=dbaas.lagoon.svc:5000

RUN curl -sSL https://github.com/uselagoon/lagoon-linter/releases/download/v0.8.0/lagoon-linter_0.8.0_linux_amd64.tar.gz \
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
VERSION=$(shell echo $(shell git describe --abbrev=0 --tags)+$(shell git rev-parse --short=8 HEAD))
BUILD=$(shell date +%FT%T%z)
GO_VER=1.17
GO_VER=1.18
GOOS=linux
GOARCH=amd64
PKG=github.com/uselagoon/build-deploy-tool
Expand Down
41 changes: 41 additions & 0 deletions cmd/identify_ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,48 @@ func IdentifyPrimaryIngress(g generator.GeneratorInput) (string, []string, []str
return lagoonBuild.BuildValues.Route, lagoonBuild.BuildValues.Routes, lagoonBuild.BuildValues.AutogeneratedRoutes, nil
}

var autogenIngressIdentify = &cobra.Command{
Use: "autogenerated-ingress",
Aliases: []string{"ai"},
Short: "Identify all autogenerated ingress object names for a specific environment",
RunE: func(cmd *cobra.Command, args []string) error {
generator, err := generatorInput(false)
if err != nil {
return err
}
autogen, err := AutogeneratedIngressIdentification(generator)
if err != nil {
return err
}
ret := ingressIdentifyJSON{
Autogenerated: autogen,
}
retJSON, _ := json.Marshal(ret)
fmt.Println(string(retJSON))
return nil
},
}

// AutogeneratedIngressIdentification handles identifying autogenerated ingress
func AutogeneratedIngressIdentification(g generator.GeneratorInput) ([]string, error) {
lagoonBuild, err := generator.NewGenerator(
g,
)
if err != nil {
return nil, err
}

autogenIngress := []string{}
// generate the templates
for _, route := range lagoonBuild.AutogeneratedRoutes.Routes {
autogenIngress = append(autogenIngress, route.LagoonService)
}

return autogenIngress, nil
}

func init() {
identifyCmd.AddCommand(primaryIngressIdentify)
identifyCmd.AddCommand(ingressIdentify)
identifyCmd.AddCommand(autogenIngressIdentify)
}
232 changes: 232 additions & 0 deletions cmd/identify_ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,3 +533,235 @@ func TestIdentifyRoute(t *testing.T) {
})
}
}

func TestAutogeneratedIngressIdentification(t *testing.T) {
type args struct {
alertContact string
statusPageID string
projectName string
environmentName string
branch string
prNumber string
prHeadBranch string
prBaseBranch string
environmentType string
buildType string
activeEnvironment string
standbyEnvironment string
cacheNoCache string
serviceID string
secretPrefix string
projectVars string
envVars string
lagoonVersion string
lagoonYAML string
valuesFilePath string
templatePath string
}
tests := []struct {
name string
args args
want string
wantJSON string
wantRemain []string
wantautoGen []string
}{
{
name: "test13 no autogenerated routes",
args: args{
alertContact: "alertcontact",
statusPageID: "statuspageid",
projectName: "example-project",
environmentName: "main",
environmentType: "production",
buildType: "branch",
lagoonVersion: "v2.7.x",
branch: "main",
projectVars: `[{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"}]`,
envVars: `[]`,
lagoonYAML: "../test-resources/identify-ingress/test13/lagoon.yml",
templatePath: "../test-resources/output",
},
wantautoGen: []string{},
wantJSON: `{"primary":"","secondary":null,"autogenerated":[]}`,
},
{
name: "test14 only autogenerated route",
args: args{
alertContact: "alertcontact",
statusPageID: "statuspageid",
projectName: "example-project",
environmentName: "main",
environmentType: "production",
buildType: "branch",
lagoonVersion: "v2.7.x",
branch: "main",
projectVars: `[{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"}]`,
envVars: `[]`,
lagoonYAML: "../test-resources/identify-ingress/test14/lagoon.yml",
templatePath: "../test-resources/output",
},
wantautoGen: []string{"node"},
wantJSON: `{"primary":"","secondary":null,"autogenerated":["node"]}`,
},
{
name: "test15 only autogenerated route complex",
args: args{
alertContact: "alertcontact",
statusPageID: "statuspageid",
projectName: "sales-customer-support",
environmentName: "develop",
environmentType: "development",
buildType: "branch",
lagoonVersion: "v2.7.x",
branch: "develop",
projectVars: `[{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.ex1.example-web.com","scope":"internal_system"}]`,
envVars: `[]`,
lagoonYAML: "../test-resources/identify-ingress/test15/lagoon.yml",
templatePath: "../test-resources/output",
},
wantautoGen: []string{"nginx"},
wantJSON: `{"primary":"","secondary":null,"autogenerated":["nginx"]}`,
},
{
name: "test16 autogenerated routes where lagoon.name of service does not match service names",
args: args{
alertContact: "alertcontact",
statusPageID: "statuspageid",
projectName: "content-example-com",
environmentName: "feature-migration",
environmentType: "development",
buildType: "branch",
lagoonVersion: "v2.7.x",
branch: "feature/migration",
projectVars: `[{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${environment}.${project}.example.com","scope":"internal_system"}]`,
envVars: `[]`,
lagoonYAML: "../test-resources/identify-ingress/test16/lagoon.yml",
templatePath: "../test-resources/output",
},
wantautoGen: []string{"nginx-php"},
wantJSON: `{"primary":"","secondary":null,"autogenerated":["nginx-php"]}`,
},
{
name: "test17 autogenerated routes with mulitple routeable services",
args: args{
alertContact: "alertcontact",
statusPageID: "statuspageid",
projectName: "example-project",
environmentName: "main",
environmentType: "production",
buildType: "branch",
lagoonVersion: "v2.7.x",
branch: "main",
projectVars: `[{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"}]`,
envVars: `[]`,
lagoonYAML: "../test-resources/identify-ingress/test17/lagoon.yml",
templatePath: "../test-resources/output",
},
wantautoGen: []string{"nginx", "varnish"},
wantJSON: `{"primary":"","secondary":null,"autogenerated":["nginx","varnish"]}`,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// set the environment variables from args
err := os.Setenv("MONITORING_ALERTCONTACT", tt.args.alertContact)
if err != nil {
t.Errorf("%v", err)
}
err = os.Setenv("MONITORING_STATUSPAGEID", tt.args.statusPageID)
if err != nil {
t.Errorf("%v", err)
}
err = os.Setenv("PROJECT", tt.args.projectName)
if err != nil {
t.Errorf("%v", err)
}
err = os.Setenv("ENVIRONMENT", tt.args.environmentName)
if err != nil {
t.Errorf("%v", err)
}
err = os.Setenv("BRANCH", tt.args.branch)
if err != nil {
t.Errorf("%v", err)
}
err = os.Setenv("LAGOON_GIT_BRANCH", tt.args.branch)
if err != nil {
t.Errorf("%v", err)
}
err = os.Setenv("PR_NUMBER", tt.args.prNumber)
if err != nil {
t.Errorf("%v", err)
}
err = os.Setenv("PR_HEAD_BRANCH", tt.args.prHeadBranch)
if err != nil {
t.Errorf("%v", err)
}
err = os.Setenv("PR_BASE_BRANCH", tt.args.prBaseBranch)
if err != nil {
t.Errorf("%v", err)
}
err = os.Setenv("ENVIRONMENT_TYPE", tt.args.environmentType)
if err != nil {
t.Errorf("%v", err)
}
err = os.Setenv("BUILD_TYPE", tt.args.buildType)
if err != nil {
t.Errorf("%v", err)
}
err = os.Setenv("ACTIVE_ENVIRONMENT", tt.args.activeEnvironment)
if err != nil {
t.Errorf("%v", err)
}
err = os.Setenv("STANDBY_ENVIRONMENT", tt.args.standbyEnvironment)
if err != nil {
t.Errorf("%v", err)
}
err = os.Setenv("LAGOON_FASTLY_NOCACHE_SERVICE_ID", tt.args.cacheNoCache)
if err != nil {
t.Errorf("%v", err)
}
err = os.Setenv("LAGOON_PROJECT_VARIABLES", tt.args.projectVars)
if err != nil {
t.Errorf("%v", err)
}
err = os.Setenv("LAGOON_ENVIRONMENT_VARIABLES", tt.args.envVars)
if err != nil {
t.Errorf("%v", err)
}
err = os.Setenv("LAGOON_VERSION", tt.args.lagoonVersion)
if err != nil {
t.Errorf("%v", err)
}
generator, err := generatorInput(false)
if err != nil {
t.Errorf("%v", err)
}
generator.LagoonYAML = tt.args.lagoonYAML
// add dbaasclient overrides for tests
generator.DBaaSClient = dbaasclient.NewClient(dbaasclient.Client{
RetryMax: 5,
RetryWaitMin: time.Duration(10) * time.Millisecond,
RetryWaitMax: time.Duration(50) * time.Millisecond,
})

autogen, err := AutogeneratedIngressIdentification(generator)
if err != nil {
t.Errorf("%v", err)
}

if !reflect.DeepEqual(autogen, tt.wantautoGen) {
t.Errorf("returned autogen %v doesn't match want %v", autogen, tt.wantautoGen)
}

ret := ingressIdentifyJSON{
Autogenerated: autogen,
}
retJSON, _ := json.Marshal(ret)

if string(retJSON) != tt.wantJSON {
t.Errorf("returned autogen %v doesn't match want %v", string(retJSON), tt.wantJSON)
}
})
}
}
Loading

0 comments on commit fae5d53

Please sign in to comment.