diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 3a66b10c5..bec61e6cf 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -47,5 +47,11 @@ jobs: exit 1 fi + - name: Install golangci-lint + run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.59.1 + + - name: Build custom golangci-lint + run: golangci-lint custom + - name: Run golangci-lint - uses: golangci/golangci-lint-action@v6 + run: ./custom-gcl run diff --git a/Justfile b/Justfile index e6e8ca50a..c77995b6a 100644 --- a/Justfile +++ b/Justfile @@ -26,6 +26,7 @@ release-snapshot: gen-license-report # Run golangci-lint for all packages lint *ARGS: [ -f ./custom-gcl ] || golangci-lint custom + ./custom-gcl cache clean ./custom-gcl run {{ARGS}} # Check struct memory alignment and print potential improvements diff --git a/cmd/vclusterctl/cmd/root.go b/cmd/vclusterctl/cmd/root.go index 01034347f..a18801bd6 100644 --- a/cmd/vclusterctl/cmd/root.go +++ b/cmd/vclusterctl/cmd/root.go @@ -2,6 +2,7 @@ package cmd import ( "context" + "errors" "fmt" "os" "path/filepath" @@ -27,13 +28,17 @@ import ( ) // NewRootCmd returns a new root command -func NewRootCmd(log log.Logger, globalFlags *flags.GlobalFlags) *cobra.Command { +func NewRootCmd(log log.Logger) *cobra.Command { return &cobra.Command{ Use: "vcluster", SilenceUsage: true, SilenceErrors: true, Short: "Welcome to vcluster!", - PersistentPreRun: func(_ *cobra.Command, _ []string) { + PersistentPreRunE: func(_ *cobra.Command, _ []string) error { + if globalFlags == nil { + return errors.New("nil globalFlags") + } + if globalFlags.Config == "" { var err error globalFlags.Config, err = config.DefaultFilePath() @@ -52,6 +57,8 @@ func NewRootCmd(log log.Logger, globalFlags *flags.GlobalFlags) *cobra.Command { } else { log.SetLevel(logrus.InfoLevel) } + + return nil }, Long: `vcluster root command`, } @@ -84,10 +91,11 @@ func Execute() { } } +var globalFlags *flags.GlobalFlags + // BuildRoot creates a new root command from the func BuildRoot(log log.Logger) (*cobra.Command, *flags.GlobalFlags, error) { - var globalFlags *flags.GlobalFlags - rootCmd := NewRootCmd(log, globalFlags) + rootCmd := NewRootCmd(log) persistentFlags := rootCmd.PersistentFlags() globalFlags = flags.SetGlobalFlags(persistentFlags, log) diff --git a/pkg/controllers/resources/ingresses/syncer_test.go b/pkg/controllers/resources/ingresses/syncer_test.go index ad52f0b37..cee918cce 100644 --- a/pkg/controllers/resources/ingresses/syncer_test.go +++ b/pkg/controllers/resources/ingresses/syncer_test.go @@ -413,7 +413,7 @@ func TestSync(t *testing.T) { "vcluster.loft.sh/object-namespace": baseIngress.Namespace, translate.UIDAnnotation: "", "alb.ingress.kubernetes.io/actions.testservice-x-test-x-suffix": `{"forwardConfig":{"targetGroups":[{"serviceName":"nginx-service-x-test-x-suffix","servicePort":"80","weight":100}]}}`, - "alb.ingress.kubernetes.io/actions.ssl-redirect-x-test-x-suffix": `{"type":"redirect","forwardConfig":{},"redirectConfig":{"Port":"443","Protocol":"HTTPS","StatusCode":"HTTP_301"}}`, + "alb.ingress.kubernetes.io/actions.ssl-redirect-x-test-x-suffix": `{"redirectConfig":{"Port":"443","Protocol":"HTTPS","StatusCode":"HTTP_301"},"type":"redirect","forwardConfig":{}}`, }, }, },