Skip to content

Commit bb3cd05

Browse files
Merge branch 'main' into mc/require-ssl-mod
2 parents 2092557 + 9e9b44d commit bb3cd05

37 files changed

+2857
-328
lines changed

README.md

-5
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,3 @@ See [Remove Env From Service](./docs/remove-env-from-service.md)
9797

9898
### Remove a service entirely
9999
See [Remove Service Entirely](./docs/remove-service.md)
100-
101-
## Notes for Upgrading to version 12.x.y
102-
From version 12 the custom migrations are removed.
103-
If you were using git and now you need to migrate to db mode, first you need to upgrade to version 11.20.0, and wait for the custom migrations to be applied and then you can upgrade to versions greater than 12.x.y.
104-

charts/kuberpult/templates/cd-service.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,8 @@ spec:
270270
value: "{{ .Values.db.connections.cd.maxOpen }}"
271271
- name: KUBERPULT_DB_MAX_IDLE_CONNECTIONS
272272
value: "{{ .Values.db.connections.cd.maxIdle }}"
273+
- name: KUBERPULT_CHECK_CUSTOM_MIGRATIONS
274+
value: "{{ .Values.db.checkCustomMigrations }}"
273275
{{- end }}
274276
- name: KUBERPULT_ALLOW_LONG_APP_NAMES
275277
value: "{{ .Values.cd.allowLongAppNames }}"
@@ -281,6 +283,10 @@ spec:
281283
- name: KUBERPULT_MINOR_REGEXES
282284
value: {{ .Values.cd.minorRegexes | join "," | quote }}
283285
{{- end }}
286+
- name: KUBERPULT_MIGRATION_SERVER
287+
value: kuberpult-manifest-repo-export-service:8443
288+
- name: KUBERPULT_MIGRATION_SERVER_SECURE
289+
value: "false"
284290
- name: KUBERPULT_GRPC_MAX_RECV_MSG_SIZE
285291
value: "{{ .Values.cd.grpcMaxRecvMsgSize }}"
286292
volumeMounts:

charts/kuberpult/templates/manifest-repo-export-service.yaml

+4-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
{{ fail ".Values.db.dbOption does not contain a valid value (postgreSQL)."}}
1919
{{ end -}}
2020

21-
# the export service is only enabled, if the DB is enabled
22-
{{- if (eq .Values.db.dbOption "postgreSQL") }}
21+
# the export service is only enabled, if the DB is enabled and the `enabled` flag is true
22+
{{- if (and (eq .Values.db.dbOption "postgreSQL") (.Values.manifestRepoExport.enabled))}}
2323

2424
---
2525
apiVersion: apps/v1
@@ -235,6 +235,8 @@ spec:
235235
value: "{{ .Values.git.releaseVersionsLimit }}"
236236
- name: KUBERPULT_MINIMIZE_EXPORTED_DATA
237237
value: "{{ .Values.git.minimizeExportedData }}"
238+
- name: KUBERPULT_CHECK_CUSTOM_MIGRATIONS
239+
value: "{{ .Values.db.checkCustomMigrations }}"
238240
volumeMounts:
239241
- name: repository
240242
# The repository volume, an emptyDir, is mounted to the kp directory.

charts/kuberpult/tests/charts_test.go

+103
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,14 @@ ingress:
181181
Name: "KUBERPULT_DB_OPTION",
182182
Value: "postgreSQL",
183183
},
184+
{
185+
Name: "KUBERPULT_MIGRATION_SERVER",
186+
Value: "kuberpult-manifest-repo-export-service:8443",
187+
},
188+
{
189+
Name: "KUBERPULT_MIGRATION_SERVER_SECURE",
190+
Value: "false",
191+
},
184192
{
185193
Name: "KUBERPULT_GRPC_MAX_RECV_MSG_SIZE",
186194
Value: "4",
@@ -639,6 +647,44 @@ db:
639647
},
640648
ExpectedMissing: []core.EnvVar{},
641649
},
650+
{
651+
Name: "Check for custom Migrations",
652+
Values: `
653+
git:
654+
url: "testURL"
655+
ingress:
656+
domainName: "kuberpult-example.com"
657+
db:
658+
dbOption: "postgreSQL"
659+
checkCustomMigrations: false
660+
`,
661+
ExpectedEnvs: []core.EnvVar{
662+
{
663+
Name: "KUBERPULT_CHECK_CUSTOM_MIGRATIONS",
664+
Value: "false",
665+
},
666+
},
667+
ExpectedMissing: []core.EnvVar{},
668+
},
669+
{
670+
Name: "Check for custom Migrations",
671+
Values: `
672+
git:
673+
url: "testURL"
674+
ingress:
675+
domainName: "kuberpult-example.com"
676+
db:
677+
dbOption: "postgreSQL"
678+
checkCustomMigrations: true
679+
`,
680+
ExpectedEnvs: []core.EnvVar{
681+
{
682+
Name: "KUBERPULT_CHECK_CUSTOM_MIGRATIONS",
683+
Value: "true",
684+
},
685+
},
686+
ExpectedMissing: []core.EnvVar{},
687+
},
642688
}
643689

644690
for _, tc := range tcs {
@@ -1942,3 +1988,60 @@ func makeAllIngressPaths(withDex, withUi, withOldApi, withNewApi bool) []network
19421988
}
19431989
return result
19441990
}
1991+
func TestManifestExportServiceDisabled(t *testing.T) {
1992+
tcs := []struct {
1993+
Name string
1994+
Values string
1995+
ShouldExist bool
1996+
}{
1997+
{
1998+
Name: "Disabled Export Service",
1999+
Values: `
2000+
git:
2001+
url: "checkThisValue"
2002+
ingress:
2003+
domainName: "kuberpult-example.com"
2004+
db:
2005+
dbOption: "postgreSQL"
2006+
writeEslTableOnly: false
2007+
manifestRepoExport:
2008+
enabled: false
2009+
`,
2010+
ShouldExist: false,
2011+
},
2012+
{
2013+
Name: "Enabled Export Service",
2014+
Values: `
2015+
git:
2016+
url: "checkThisValue"
2017+
ingress:
2018+
domainName: "kuberpult-example.com"
2019+
db:
2020+
dbOption: "postgreSQL"
2021+
writeEslTableOnly: false
2022+
manifestRepoExport:
2023+
enabled: true
2024+
`,
2025+
ShouldExist: true,
2026+
},
2027+
}
2028+
2029+
for _, tc := range tcs {
2030+
tc := tc
2031+
t.Run(tc.Name, func(t *testing.T) {
2032+
testDirName := t.TempDir()
2033+
outputFile, err := runHelm(t, []byte(tc.Values), testDirName)
2034+
if err != nil {
2035+
t.Fatalf(fmt.Sprintf("%v", err))
2036+
}
2037+
if out, err := getDeployments(outputFile); err != nil {
2038+
t.Fatalf(fmt.Sprintf("%v", err))
2039+
} else {
2040+
_, found := out["kuberpult-manifest-repo-export-service"]
2041+
if found != tc.ShouldExist {
2042+
t.Fatalf("Expected existence: %t, got: %t", tc.ShouldExist, found)
2043+
}
2044+
}
2045+
})
2046+
}
2047+
}

charts/kuberpult/values.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,13 @@ db:
162162
rollout:
163163
maxOpen: 100
164164
maxIdle: 20
165+
# Kuberpult only checks for custom migrations if this flag is enabled. Otherwise, it skips them entirely, assuming
166+
# that there is no information we want to migrate from an existing manifest repository to the database.
167+
# You should only enable this flag, if you want to do a one-step upgrade of kuberpult from a (relatively old) version that still uses git as storage.
168+
# If you are already using the database, ignore this flag.
169+
checkCustomMigrations: false
165170
manifestRepoExport:
171+
enabled: true
166172
image: kuberpult-manifest-repo-export-service
167173
service:
168174
annotations: {}

cli/pkg/cmd/cli.go

+2
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ func RunCLI() ReturnCode {
8888
return handleReleaseTrain(*kpClientParams, subflags)
8989
case "get-commit-deployments":
9090
return handleGetCommitDeployments(*kpClientParams, subflags)
91+
case "delete-environment":
92+
return handleDeleteEnvironment(*kpClientParams, subflags)
9193
default:
9294
log.Printf("unknown subcommand %s\n", subcommand)
9395
return ReturnCodeInvalidArguments

cli/pkg/cmd/handlers.go

+29
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121

2222
"github.com/freiheit-com/kuberpult/cli/pkg/cli_utils"
2323
"github.com/freiheit-com/kuberpult/cli/pkg/deployments"
24+
"github.com/freiheit-com/kuberpult/cli/pkg/environments"
2425
"github.com/freiheit-com/kuberpult/cli/pkg/locks"
2526
"github.com/freiheit-com/kuberpult/cli/pkg/releasetrain"
2627

@@ -212,3 +213,31 @@ func handleGetCommitDeployments(kpClientParams kuberpultClientParameters, args [
212213
}
213214
return ReturnCodeSuccess
214215
}
216+
217+
func handleDeleteEnvironment(kpClientParams kuberpultClientParameters, args []string) ReturnCode {
218+
parsedArgs, err := environments.ParseArgsDeleteEnvironment(args)
219+
if err != nil {
220+
log.Printf("error while parsing command line args, error: %v", err)
221+
return ReturnCodeInvalidArguments
222+
}
223+
224+
authParams := kutil.AuthenticationParameters{
225+
IapToken: kpClientParams.iapToken,
226+
DexToken: kpClientParams.dexToken,
227+
AuthorName: kpClientParams.authorName,
228+
AuthorEmail: kpClientParams.authorEmail,
229+
}
230+
231+
requestParameters := kutil.RequestParameters{
232+
Url: &kpClientParams.url,
233+
Retries: kpClientParams.retries,
234+
HttpTimeout: cli_utils.HttpDefaultTimeout,
235+
}
236+
237+
if err = environments.HandleDeleteEnvironment(requestParameters, authParams, parsedArgs); err != nil {
238+
log.Printf("error on delete environment, error: %v", err)
239+
return ReturnCodeFailure
240+
}
241+
242+
return ReturnCodeSuccess
243+
}

cli/pkg/environments/delete.go

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*This file is part of kuberpult.
2+
3+
Kuberpult is free software: you can redistribute it and/or modify
4+
it under the terms of the Expat(MIT) License as published by
5+
the Free Software Foundation.
6+
7+
Kuberpult is distributed in the hope that it will be useful,
8+
but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
MIT License for more details.
11+
12+
You should have received a copy of the MIT License
13+
along with kuberpult. If not, see <https://directory.fsf.org/wiki/License:Expat>.
14+
15+
Copyright freiheit.com*/
16+
/*
17+
This file is part of kuberpult.
18+
19+
Kuberpult is free software: you can redistribute it and/or modify
20+
it under the terms of the Expat(MIT) License as published by
21+
the Free Software Foundation.
22+
23+
Kuberpult is distributed in the hope that it will be useful,
24+
but WITHOUT ANY WARRANTY; without even the implied warranty of
25+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26+
MIT License for more details.
27+
28+
You should have received a copy of the MIT License
29+
along with kuberpult. If not, see <https://directory.fsf.org/wiki/License:Expat>.
30+
31+
Copyright freiheit.com
32+
*/
33+
package environments
34+
35+
import (
36+
"fmt"
37+
"net/http"
38+
urllib "net/url"
39+
40+
"github.com/freiheit-com/kuberpult/cli/pkg/cli_utils"
41+
kutil "github.com/freiheit-com/kuberpult/cli/pkg/kuberpult_utils"
42+
)
43+
44+
type DeleteEnvironmentParameters struct {
45+
Environment string
46+
}
47+
48+
func HandleDeleteEnvironment(requestParams kutil.RequestParameters, authParams kutil.AuthenticationParameters, params *DeleteEnvironmentParameters) error {
49+
req, err := createHttpRequest(*requestParams.Url, authParams, params)
50+
if err != nil {
51+
return fmt.Errorf("error while preparing HTTP request, error: %w", err)
52+
}
53+
54+
if err = cli_utils.IssueHttpRequest(*req, requestParams.Retries, requestParams.HttpTimeout); err != nil {
55+
return fmt.Errorf("error while issuing HTTP request, error: %v", err)
56+
}
57+
58+
return nil
59+
}
60+
61+
func createHttpRequest(url string, authParams kutil.AuthenticationParameters, parameters *DeleteEnvironmentParameters) (*http.Request, error) {
62+
urlStruct, err := urllib.Parse(url)
63+
if err != nil {
64+
return nil, fmt.Errorf("the provided url %s is invalid, error: %w", url, err)
65+
}
66+
67+
path := "/api/environments/" + parameters.Environment
68+
69+
req, err := http.NewRequest(http.MethodDelete, urlStruct.JoinPath(path).String(), nil)
70+
if err != nil {
71+
return nil, fmt.Errorf("error creating the HTTP request, error: %w", err)
72+
}
73+
74+
if authParams.IapToken != nil {
75+
req.Header.Add("Proxy-Authorization", "Bearer "+*authParams.IapToken)
76+
}
77+
78+
if authParams.DexToken != nil {
79+
req.Header.Add("Authorization", "Bearer "+*authParams.DexToken)
80+
}
81+
82+
return req, nil
83+
}

0 commit comments

Comments
 (0)