Skip to content

Commit

Permalink
Update module references (#98)
Browse files Browse the repository at this point in the history
validation support for `runtime` section in radixconfig
add flag `--strict-validation` in command validate `radix-config`
  • Loading branch information
nilsgstrabo authored Jun 18, 2024
1 parent e73944f commit 723000d
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 166 deletions.
66 changes: 30 additions & 36 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,38 @@
"version": "0.2.0",
"configurations": [
{
"name": "Lauch radix-cli login",
"name": "Launch radix-cli login",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/main.go",
"program": "${workspaceFolder}/cli/rx/main.go",
"env": {},
"args": ["login"]
},
{
"name": "Lauch radix-cli logout",
"name": "Launch radix-cli logout",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/main.go",
"program": "${workspaceFolder}/cli/rx/main.go",
"env": {},
"args": ["logout"]
},
{
"name": "Lauch radix-cli list applications",
"name": "Launch radix-cli list applications",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/main.go",
"program": "${workspaceFolder}/cli/rx/main.go",
"env": {},
"args": ["get", "application"]
},
{
"name": "Lauch radix-cli build deploy application",
"name": "Launch radix-cli build deploy application",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/main.go",
"program": "${workspaceFolder}/cli/rx/main.go",
"env": {
"APP_SERVICE_ACCOUNT_TOKEN": "token"
},
Expand All @@ -56,11 +56,11 @@
]
},
{
"name": "Lauch radix-cli deploy application",
"name": "Launch radix-cli deploy application",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/main.go",
"program": "${workspaceFolder}/cli/rx/main.go",
"env": {
"APP_SERVICE_ACCOUNT_TOKEN": "token"
},
Expand All @@ -79,11 +79,11 @@
]
},
{
"name": "Lauch radix-cli set environment secret",
"name": "Launch radix-cli set environment secret",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/main.go",
"program": "${workspaceFolder}/cli/rx/main.go",
"env": {
"APP_SERVICE_ACCOUNT_TOKEN": "token"
},
Expand All @@ -106,11 +106,11 @@
]
},
{
"name": "Lauch radix-cli get logs component",
"name": "Launch radix-cli get logs component",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/main.go",
"program": "${workspaceFolder}/cli/rx/main.go",
"env": {
"APP_SERVICE_ACCOUNT_TOKEN": "token"
},
Expand All @@ -129,11 +129,11 @@
]
},
{
"name": "Lauch radix-cli get logs environment",
"name": "Launch radix-cli get logs environment",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/main.go",
"program": "${workspaceFolder}/cli/rx/main.go",
"env": {
"APP_SERVICE_ACCOUNT_TOKEN": "token"
},
Expand All @@ -150,11 +150,11 @@
]
},
{
"name": "Lauch radix-cli get logs job",
"name": "Launch radix-cli get logs job",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/main.go",
"program": "${workspaceFolder}/cli/rx/main.go",
"env": {
"APP_SERVICE_ACCOUNT_TOKEN": "token"
},
Expand All @@ -172,11 +172,11 @@
]
},
{
"name": "Lauch radix-cli get environment from branch",
"name": "Launch radix-cli get environment from branch",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/main.go",
"program": "${workspaceFolder}/cli/rx/main.go",
"env": {
"APP_SERVICE_ACCOUNT_TOKEN": "token"
},
Expand All @@ -191,11 +191,11 @@
]
},
{
"name": "Lauch radix-cli get application",
"name": "Launch radix-cli get application",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/main.go",
"program": "${workspaceFolder}/cli/rx/main.go",
"env": {
"APP_SERVICE_ACCOUNT_TOKEN": "token"
},
Expand All @@ -210,11 +210,11 @@
]
},
{
"name": "Lauch radix-cli restart component",
"name": "Launch radix-cli restart component",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/main.go",
"program": "${workspaceFolder}/cli/rx/main.go",
"env": {
"APP_SERVICE_ACCOUNT_TOKEN": "token"
},
Expand All @@ -227,23 +227,17 @@
"--environment", "master",
"--component", "www"
]
}
,
},
{
"name": "Launch radix-cli regenerate machine user token",
"name": "Launch radix-cli validate radix-config",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/main.go",
"env": {
"APP_SERVICE_ACCOUNT_TOKEN": "token"
},
"program": "${workspaceFolder}/cli/rx/main.go",
"args": [
"--token-environment",
"--context", "playground",
"set",
"machine-user-token",
"--application", "echo"
"validate",
"radix-config",
"-f", "/home/nst/go/src/github.com/nilsgstrabo/radix-job-demo/radixconfig.yaml"
]
}
]
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.22-alpine3.19 as builder
FROM golang:1.22-alpine3.20 as builder

ENV GO111MODULE=on

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ HAS_GORELEASER := $(shell command -v goreleaser;)

bootstrap:
ifndef HAS_SWAGGER
go install github.com/go-swagger/go-swagger/cmd/swagger@v0.30.5
go install github.com/go-swagger/go-swagger/cmd/swagger@v0.31.0
endif
ifndef HAS_GOLANGCI_LINT
go install github.com/golangci/golangci-lint/cmd/[email protected]
Expand Down
13 changes: 8 additions & 5 deletions cmd/createPromotePipelineJob.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
package cmd

import (
"errors"
"fmt"

apiclient "github.com/equinor/radix-cli/generated-client/client"
"github.com/equinor/radix-cli/generated-client/client/environment"
"github.com/pkg/errors"

log "github.com/sirupsen/logrus"

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

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

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

resp, err := apiClient.Environment.GetEnvironment(params, nil)
if err != nil {
return "", errors.Wrap(err, "Failed to get environment details")
return "", fmt.Errorf("failed to get environment details: %w", err)
}

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

return resp.Payload.ActiveDeployment.Name, nil
Expand Down
3 changes: 1 addition & 2 deletions cmd/logsPipelineJob.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ package cmd
import (
"errors"
"fmt"
"slices"
"strings"
"time"

"k8s.io/utils/strings/slices"

apiclient "github.com/equinor/radix-cli/generated-client/client"
"github.com/equinor/radix-cli/generated-client/client/pipeline_job"
"github.com/equinor/radix-cli/pkg/client"
Expand Down
26 changes: 22 additions & 4 deletions cmd/validateRadixConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
package cmd

import (
"errors"
"fmt"
"os"

"github.com/equinor/radix-cli/pkg/client"
"github.com/equinor/radix-cli/pkg/flagnames"
radixv1 "github.com/equinor/radix-operator/pkg/apis/radix/v1"
"github.com/equinor/radix-operator/pkg/apis/radixvalidators"
"github.com/pkg/errors"
"github.com/santhosh-tekuri/jsonschema/v5"
_ "github.com/santhosh-tekuri/jsonschema/v5/httploader"
"github.com/spf13/cobra"
Expand All @@ -34,6 +34,15 @@ var validateRadixConfigCmd = &cobra.Command{
Use: "radix-config",
Short: "Validate radixconfig.yaml",
Long: `Check radixconfig.yaml for structural and logical errors`,
Example: `# Validate radixconfig.yaml in current directory:
rx validate radix-config
# Specify path to radixconfig to validate:
rx validate radix-config --config-file /path/to/anyradixconfig.yaml
# Validate radixconfig without strict validation:
rx validate radix-config --strict-validation=false
`,
Run: func(cmd *cobra.Command, args []string) {
radixconfig, err := cmd.Flags().GetString(flagnames.ConfigFile)
if err != nil {
Expand All @@ -53,6 +62,12 @@ var validateRadixConfigCmd = &cobra.Command{
os.Exit(1)
}

strictValidation, err := cmd.Flags().GetBool(flagnames.StrictValidation)
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}

fmt.Fprintf(os.Stderr, "Validating %s\n", radixconfig)
if _, err := os.Stat(radixconfig); errors.Is(err, os.ErrNotExist) {
fmt.Fprintln(os.Stderr, "RadixConfig file not found")
Expand Down Expand Up @@ -90,9 +105,11 @@ var validateRadixConfigCmd = &cobra.Command{
validationErrors = append(validationErrors, err)
}

err = strictUnmarshalValidation(raw)
if err != nil {
validationErrors = append(validationErrors, err)
if strictValidation {
err = strictUnmarshalValidation(raw)
if err != nil {
validationErrors = append(validationErrors, err)
}
}

if len(validationErrors) == 0 {
Expand Down Expand Up @@ -168,6 +185,7 @@ func init() {
validateCmd.AddCommand(validateRadixConfigCmd)
validateRadixConfigCmd.Flags().StringP(flagnames.ConfigFile, "f", "radixconfig.yaml", "Name of the radixconfig file. Defaults to radixconfig.yaml in current directory")
validateRadixConfigCmd.Flags().BoolP(flagnames.Print, "p", false, "Print parsed config file")
validateRadixConfigCmd.Flags().Bool(flagnames.StrictValidation, true, "Enable or disable strict schema validation, which will check for unknown fields in the radixconfig file")
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")

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

0 comments on commit 723000d

Please sign in to comment.