Skip to content

Commit 723000d

Browse files
authored
Update module references (#98)
validation support for `runtime` section in radixconfig add flag `--strict-validation` in command validate `radix-config`
1 parent e73944f commit 723000d

9 files changed

+122
-166
lines changed

.vscode/launch.json

+30-36
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,38 @@
66
"version": "0.2.0",
77
"configurations": [
88
{
9-
"name": "Lauch radix-cli login",
9+
"name": "Launch radix-cli login",
1010
"type": "go",
1111
"request": "launch",
1212
"mode": "auto",
13-
"program": "${workspaceFolder}/main.go",
13+
"program": "${workspaceFolder}/cli/rx/main.go",
1414
"env": {},
1515
"args": ["login"]
1616
},
1717
{
18-
"name": "Lauch radix-cli logout",
18+
"name": "Launch radix-cli logout",
1919
"type": "go",
2020
"request": "launch",
2121
"mode": "auto",
22-
"program": "${workspaceFolder}/main.go",
22+
"program": "${workspaceFolder}/cli/rx/main.go",
2323
"env": {},
2424
"args": ["logout"]
2525
},
2626
{
27-
"name": "Lauch radix-cli list applications",
27+
"name": "Launch radix-cli list applications",
2828
"type": "go",
2929
"request": "launch",
3030
"mode": "auto",
31-
"program": "${workspaceFolder}/main.go",
31+
"program": "${workspaceFolder}/cli/rx/main.go",
3232
"env": {},
3333
"args": ["get", "application"]
3434
},
3535
{
36-
"name": "Lauch radix-cli build deploy application",
36+
"name": "Launch radix-cli build deploy application",
3737
"type": "go",
3838
"request": "launch",
3939
"mode": "auto",
40-
"program": "${workspaceFolder}/main.go",
40+
"program": "${workspaceFolder}/cli/rx/main.go",
4141
"env": {
4242
"APP_SERVICE_ACCOUNT_TOKEN": "token"
4343
},
@@ -56,11 +56,11 @@
5656
]
5757
},
5858
{
59-
"name": "Lauch radix-cli deploy application",
59+
"name": "Launch radix-cli deploy application",
6060
"type": "go",
6161
"request": "launch",
6262
"mode": "auto",
63-
"program": "${workspaceFolder}/main.go",
63+
"program": "${workspaceFolder}/cli/rx/main.go",
6464
"env": {
6565
"APP_SERVICE_ACCOUNT_TOKEN": "token"
6666
},
@@ -79,11 +79,11 @@
7979
]
8080
},
8181
{
82-
"name": "Lauch radix-cli set environment secret",
82+
"name": "Launch radix-cli set environment secret",
8383
"type": "go",
8484
"request": "launch",
8585
"mode": "auto",
86-
"program": "${workspaceFolder}/main.go",
86+
"program": "${workspaceFolder}/cli/rx/main.go",
8787
"env": {
8888
"APP_SERVICE_ACCOUNT_TOKEN": "token"
8989
},
@@ -106,11 +106,11 @@
106106
]
107107
},
108108
{
109-
"name": "Lauch radix-cli get logs component",
109+
"name": "Launch radix-cli get logs component",
110110
"type": "go",
111111
"request": "launch",
112112
"mode": "auto",
113-
"program": "${workspaceFolder}/main.go",
113+
"program": "${workspaceFolder}/cli/rx/main.go",
114114
"env": {
115115
"APP_SERVICE_ACCOUNT_TOKEN": "token"
116116
},
@@ -129,11 +129,11 @@
129129
]
130130
},
131131
{
132-
"name": "Lauch radix-cli get logs environment",
132+
"name": "Launch radix-cli get logs environment",
133133
"type": "go",
134134
"request": "launch",
135135
"mode": "auto",
136-
"program": "${workspaceFolder}/main.go",
136+
"program": "${workspaceFolder}/cli/rx/main.go",
137137
"env": {
138138
"APP_SERVICE_ACCOUNT_TOKEN": "token"
139139
},
@@ -150,11 +150,11 @@
150150
]
151151
},
152152
{
153-
"name": "Lauch radix-cli get logs job",
153+
"name": "Launch radix-cli get logs job",
154154
"type": "go",
155155
"request": "launch",
156156
"mode": "auto",
157-
"program": "${workspaceFolder}/main.go",
157+
"program": "${workspaceFolder}/cli/rx/main.go",
158158
"env": {
159159
"APP_SERVICE_ACCOUNT_TOKEN": "token"
160160
},
@@ -172,11 +172,11 @@
172172
]
173173
},
174174
{
175-
"name": "Lauch radix-cli get environment from branch",
175+
"name": "Launch radix-cli get environment from branch",
176176
"type": "go",
177177
"request": "launch",
178178
"mode": "auto",
179-
"program": "${workspaceFolder}/main.go",
179+
"program": "${workspaceFolder}/cli/rx/main.go",
180180
"env": {
181181
"APP_SERVICE_ACCOUNT_TOKEN": "token"
182182
},
@@ -191,11 +191,11 @@
191191
]
192192
},
193193
{
194-
"name": "Lauch radix-cli get application",
194+
"name": "Launch radix-cli get application",
195195
"type": "go",
196196
"request": "launch",
197197
"mode": "auto",
198-
"program": "${workspaceFolder}/main.go",
198+
"program": "${workspaceFolder}/cli/rx/main.go",
199199
"env": {
200200
"APP_SERVICE_ACCOUNT_TOKEN": "token"
201201
},
@@ -210,11 +210,11 @@
210210
]
211211
},
212212
{
213-
"name": "Lauch radix-cli restart component",
213+
"name": "Launch radix-cli restart component",
214214
"type": "go",
215215
"request": "launch",
216216
"mode": "auto",
217-
"program": "${workspaceFolder}/main.go",
217+
"program": "${workspaceFolder}/cli/rx/main.go",
218218
"env": {
219219
"APP_SERVICE_ACCOUNT_TOKEN": "token"
220220
},
@@ -227,23 +227,17 @@
227227
"--environment", "master",
228228
"--component", "www"
229229
]
230-
}
231-
,
230+
},
232231
{
233-
"name": "Launch radix-cli regenerate machine user token",
232+
"name": "Launch radix-cli validate radix-config",
234233
"type": "go",
235234
"request": "launch",
236235
"mode": "auto",
237-
"program": "${workspaceFolder}/main.go",
238-
"env": {
239-
"APP_SERVICE_ACCOUNT_TOKEN": "token"
240-
},
236+
"program": "${workspaceFolder}/cli/rx/main.go",
241237
"args": [
242-
"--token-environment",
243-
"--context", "playground",
244-
"set",
245-
"machine-user-token",
246-
"--application", "echo"
238+
"validate",
239+
"radix-config",
240+
"-f", "/home/nst/go/src/github.com/nilsgstrabo/radix-job-demo/radixconfig.yaml"
247241
]
248242
}
249243
]

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.22-alpine3.19 as builder
1+
FROM golang:1.22-alpine3.20 as builder
22

33
ENV GO111MODULE=on
44

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ HAS_GORELEASER := $(shell command -v goreleaser;)
2222

2323
bootstrap:
2424
ifndef HAS_SWAGGER
25-
go install github.com/go-swagger/go-swagger/cmd/swagger@v0.30.5
25+
go install github.com/go-swagger/go-swagger/cmd/swagger@v0.31.0
2626
endif
2727
ifndef HAS_GOLANGCI_LINT
2828
go install github.com/golangci/golangci-lint/cmd/[email protected]

cmd/createPromotePipelineJob.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@
1515
package cmd
1616

1717
import (
18+
"errors"
19+
"fmt"
20+
1821
apiclient "github.com/equinor/radix-cli/generated-client/client"
1922
"github.com/equinor/radix-cli/generated-client/client/environment"
20-
"github.com/pkg/errors"
23+
2124
log "github.com/sirupsen/logrus"
2225

2326
"github.com/equinor/radix-cli/generated-client/client/application"
@@ -46,10 +49,10 @@ var createPromotePipelineJobCmd = &cobra.Command{
4649
follow, _ := cmd.Flags().GetBool(flagnames.Follow)
4750

4851
if !useActiveDeployment && deploymentName == "" {
49-
return errors.New("Specifying deployment name or setting use-active-deployment is required")
52+
return errors.New("specifying deployment name or setting use-active-deployment is required")
5053
}
5154
if useActiveDeployment && deploymentName != "" {
52-
return errors.New("You cannot set use-active-deployment and specify deployment name at the same time")
55+
return errors.New("you cannot set use-active-deployment and specify deployment name at the same time")
5356
}
5457

5558
if appName == nil || *appName == "" || fromEnvironment == "" || toEnvironment == "" {
@@ -103,11 +106,11 @@ func getActiveDeploymentName(apiClient *apiclient.Radixapi, appName, envName str
103106

104107
resp, err := apiClient.Environment.GetEnvironment(params, nil)
105108
if err != nil {
106-
return "", errors.Wrap(err, "Failed to get environment details")
109+
return "", fmt.Errorf("failed to get environment details: %w", err)
107110
}
108111

109112
if resp.Payload.ActiveDeployment == nil || resp.Payload.ActiveDeployment.Name == "" {
110-
return "", errors.Errorf("Environment '%s' does not have any active deployments", envName)
113+
return "", fmt.Errorf("environment '%s' does not have any active deployments", envName)
111114
}
112115

113116
return resp.Payload.ActiveDeployment.Name, nil

cmd/logsPipelineJob.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@ package cmd
1717
import (
1818
"errors"
1919
"fmt"
20+
"slices"
2021
"strings"
2122
"time"
2223

23-
"k8s.io/utils/strings/slices"
24-
2524
apiclient "github.com/equinor/radix-cli/generated-client/client"
2625
"github.com/equinor/radix-cli/generated-client/client/pipeline_job"
2726
"github.com/equinor/radix-cli/pkg/client"

cmd/validateRadixConfig.go

+22-4
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
package cmd
1616

1717
import (
18+
"errors"
1819
"fmt"
1920
"os"
2021

2122
"github.com/equinor/radix-cli/pkg/client"
2223
"github.com/equinor/radix-cli/pkg/flagnames"
2324
radixv1 "github.com/equinor/radix-operator/pkg/apis/radix/v1"
2425
"github.com/equinor/radix-operator/pkg/apis/radixvalidators"
25-
"github.com/pkg/errors"
2626
"github.com/santhosh-tekuri/jsonschema/v5"
2727
_ "github.com/santhosh-tekuri/jsonschema/v5/httploader"
2828
"github.com/spf13/cobra"
@@ -34,6 +34,15 @@ var validateRadixConfigCmd = &cobra.Command{
3434
Use: "radix-config",
3535
Short: "Validate radixconfig.yaml",
3636
Long: `Check radixconfig.yaml for structural and logical errors`,
37+
Example: `# Validate radixconfig.yaml in current directory:
38+
rx validate radix-config
39+
40+
# Specify path to radixconfig to validate:
41+
rx validate radix-config --config-file /path/to/anyradixconfig.yaml
42+
43+
# Validate radixconfig without strict validation:
44+
rx validate radix-config --strict-validation=false
45+
`,
3746
Run: func(cmd *cobra.Command, args []string) {
3847
radixconfig, err := cmd.Flags().GetString(flagnames.ConfigFile)
3948
if err != nil {
@@ -53,6 +62,12 @@ var validateRadixConfigCmd = &cobra.Command{
5362
os.Exit(1)
5463
}
5564

65+
strictValidation, err := cmd.Flags().GetBool(flagnames.StrictValidation)
66+
if err != nil {
67+
fmt.Fprintln(os.Stderr, err.Error())
68+
os.Exit(1)
69+
}
70+
5671
fmt.Fprintf(os.Stderr, "Validating %s\n", radixconfig)
5772
if _, err := os.Stat(radixconfig); errors.Is(err, os.ErrNotExist) {
5873
fmt.Fprintln(os.Stderr, "RadixConfig file not found")
@@ -90,9 +105,11 @@ var validateRadixConfigCmd = &cobra.Command{
90105
validationErrors = append(validationErrors, err)
91106
}
92107

93-
err = strictUnmarshalValidation(raw)
94-
if err != nil {
95-
validationErrors = append(validationErrors, err)
108+
if strictValidation {
109+
err = strictUnmarshalValidation(raw)
110+
if err != nil {
111+
validationErrors = append(validationErrors, err)
112+
}
96113
}
97114

98115
if len(validationErrors) == 0 {
@@ -168,6 +185,7 @@ func init() {
168185
validateCmd.AddCommand(validateRadixConfigCmd)
169186
validateRadixConfigCmd.Flags().StringP(flagnames.ConfigFile, "f", "radixconfig.yaml", "Name of the radixconfig file. Defaults to radixconfig.yaml in current directory")
170187
validateRadixConfigCmd.Flags().BoolP(flagnames.Print, "p", false, "Print parsed config file")
188+
validateRadixConfigCmd.Flags().Bool(flagnames.StrictValidation, true, "Enable or disable strict schema validation, which will check for unknown fields in the radixconfig file")
171189
validateRadixConfigCmd.Flags().String(flagnames.Schema, "https://raw.githubusercontent.com/equinor/radix-operator/release/json-schema/radixapplication.json", "Validate against schema. http://, file:// or path is supported")
172190

173191
// Allow but hide token-env flag so radix-github-actions won't interfere

0 commit comments

Comments
 (0)