Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable wsl linter #321

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ linters:
- unconvert
- perfsprint
- mirror
- wsl
6 changes: 6 additions & 0 deletions cmd/fetch-ocsp-response/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,20 @@ func run(_ *cobra.Command, args []string) {
if len(certs) < 2 {
continue
}

respDER, err = getOCSPResponse(certs[0], certs[1])
if err != nil {
continue
}

break
}

if respDER == nil {
if err == nil {
err = errors.New("no issuer found")
}

fmt.Fprintf(os.Stderr, "Unable to get OCSP response: %v\n", err)
os.Exit(exitCode(err))
}
Expand Down Expand Up @@ -135,12 +138,15 @@ func loadCertificates(path string) ([]*x509.Certificate, error) {
}

var certs []*x509.Certificate

for {
blk, rest := pem.Decode(data)
if blk == nil {
return certs, nil
}

data = rest

if blk.Type != "CERTIFICATE" {
continue
}
Expand Down
4 changes: 4 additions & 0 deletions cmd/nghttpx-ingress-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ func main() {
`Specify namespace/name of Service whose hostnames/IP addresses are set in Ingress resource instead of addresses of Ingress controller Pods. Takes the form namespace/name.`)

rootCmd.Flags().BoolVar(&endpointSlices, "endpoint-slices", endpointSlices, `(Deprecated) Get endpoints from EndpointSlice resource instead of Endpoints resource. EndpointSlice resource is always used regardless of this flag. Usage of Endpoints resource has been removed.`)

if err := rootCmd.Flags().MarkDeprecated("endpoint-slices", "stop using it"); err != nil {
panic(err)
}
Expand Down Expand Up @@ -264,6 +265,7 @@ func run(ctx context.Context, _ *cobra.Command, _ []string) {
log.Error(nil, "default-backend-service cannot be empty")
os.Exit(1)
}

ns, name, err := cache.SplitMetaNamespaceKey(defaultSvc)
if err != nil {
log.Error(err, "default-backend-service: Invalid Service identifier", "service", defaultSvc)
Expand Down Expand Up @@ -328,6 +330,7 @@ func run(ctx context.Context, _ *cobra.Command, _ []string) {
}
config, err = clientcmd.NewNonInteractiveDeferredLoadingClientConfig(&loadingRules, &configOverrides).ClientConfig()
}

if err != nil {
log.Error(err, "Unable to get clientConfig")
os.Exit(1)
Expand All @@ -348,6 +351,7 @@ func run(ctx context.Context, _ *cobra.Command, _ []string) {
log.Error(nil, "POD_NAME environment variable cannot be empty.")
os.Exit(1)
}

if podInfo.Namespace == "" {
log.Error(nil, "POD_NAMESPACE environment variable cannot be empty.")
os.Exit(1)
Expand Down
4 changes: 4 additions & 0 deletions pkg/controller/annotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func (ia ingressAnnotation) NewBackendConfigMapper(ctx context.Context) *nghttpx
log.Error(err, "Unexpected error while reading annotation", "annotation", defaultBackendConfigKey)
return nghttpx.NewBackendConfigMapper(nil, nil)
}

nghttpx.FixupBackendConfig(ctx, &defaultConfig)

for _, v := range config {
Expand All @@ -84,6 +85,7 @@ func (ia ingressAnnotation) NewPathConfigMapper(ctx context.Context) *nghttpx.Pa
log := klog.FromContext(ctx)

data := ia[pathConfigKey]

var config nghttpx.PathConfigMapping
if data != "" {
if err := unmarshal(ctx, []byte(data), &config); err != nil {
Expand All @@ -109,6 +111,7 @@ func (ia ingressAnnotation) NewPathConfigMapper(ctx context.Context) *nghttpx.Pa
log.Error(err, "Unexpected error while reading annotation", "annotation", defaultPathConfigKey)
return nghttpx.NewPathConfigMapper(nil, nil)
}

nghttpx.FixupPathConfig(ctx, &defaultConfig)

for _, v := range config {
Expand All @@ -125,6 +128,7 @@ func normalizePathKey(src map[string]*nghttpx.PathConfig) map[string]*nghttpx.Pa
}

dst := make(map[string]*nghttpx.PathConfig, len(src))

for k, v := range src {
if !strings.Contains(k, "/") {
dst[k+"/"] = v
Expand Down
2 changes: 2 additions & 0 deletions pkg/controller/annotation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ svc:
if !reflect.DeepEqual(bcm.DefaultBackendConfig, tt.wantDefaultConfig) {
t.Errorf("bcm.DefaultBackendConfig = %+v, want %+v", bcm.DefaultBackendConfig, tt.wantDefaultConfig)
}

if !reflect.DeepEqual(bcm.BackendConfigMapping, tt.wantConfig) {
t.Errorf("bcm.BackendConfigMapping = %+v, want %+v", bcm.BackendConfigMapping, tt.wantConfig)
}
Expand Down Expand Up @@ -167,6 +168,7 @@ example.com/alpha:
if !reflect.DeepEqual(pcm.DefaultPathConfig, tt.wantDefaultConfig) {
t.Errorf("pcm.DefaultPathConfig = %+v, want %+v", pcm.DefaultPathConfig, tt.wantDefaultConfig)
}

if !reflect.DeepEqual(pcm.PathConfigMapping, tt.wantConfig) {
t.Errorf("pcm.PathConfigMapping = %+v, want %+v", pcm.PathConfigMapping, tt.wantConfig)
}
Expand Down
Loading