mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-09 12:07:47 +00:00
SSA: prevent usage of Extract calls via forbidigo
Client-side extract calls depend on `managedFields`, which might not be available. Therefore they should not be used in production code. They are okay in test files (because the API has to be tested), in the generated code (because the various type specific APIs still need to be provided) and in unstructured.go (same reason).
This commit is contained in:
parent
99190634ab
commit
4bc9434f99
@ -25,10 +25,16 @@ issues:
|
|||||||
- linters:
|
- linters:
|
||||||
- ginkgolinter
|
- ginkgolinter
|
||||||
text: use a function call in (Eventually|Consistently)
|
text: use a function call in (Eventually|Consistently)
|
||||||
|
# SSA Extract calls are allowed in tests.
|
||||||
|
- linters:
|
||||||
|
- forbidigo
|
||||||
|
text: should not be used because managedFields was removed
|
||||||
|
path: _test.go$
|
||||||
|
|
||||||
linters:
|
linters:
|
||||||
disable-all: false # in contrast to golangci.yaml, the default set of linters remains enabled
|
disable-all: false # in contrast to golangci.yaml, the default set of linters remains enabled
|
||||||
enable: # please keep this alphabetized and in sync with golangci.yaml
|
enable: # please keep this alphabetized and in sync with golangci.yaml
|
||||||
|
- forbidigo
|
||||||
- ginkgolinter
|
- ginkgolinter
|
||||||
- gocritic
|
- gocritic
|
||||||
- govet
|
- govet
|
||||||
@ -45,6 +51,15 @@ linters-settings: # please keep this alphabetized
|
|||||||
path: ../_output/local/bin/logcheck.so
|
path: ../_output/local/bin/logcheck.so
|
||||||
description: structured logging checker
|
description: structured logging checker
|
||||||
original-url: k8s.io/logtools/logcheck
|
original-url: k8s.io/logtools/logcheck
|
||||||
|
forbidigo:
|
||||||
|
analyze-types: true
|
||||||
|
forbid:
|
||||||
|
- p: ^managedfields\.ExtractInto$
|
||||||
|
pkg: ^k8s\.io/apimachinery/pkg/util/managedfields$
|
||||||
|
msg: should not be used because managedFields was removed
|
||||||
|
- p: \.Extract
|
||||||
|
pkg: ^k8s\.io/client-go/applyconfigurations/
|
||||||
|
msg: should not be used because managedFields was removed
|
||||||
gocritic:
|
gocritic:
|
||||||
staticcheck:
|
staticcheck:
|
||||||
checks:
|
checks:
|
||||||
|
@ -26,10 +26,16 @@ issues:
|
|||||||
- linters:
|
- linters:
|
||||||
- ginkgolinter
|
- ginkgolinter
|
||||||
text: use a function call in (Eventually|Consistently)
|
text: use a function call in (Eventually|Consistently)
|
||||||
|
# SSA Extract calls are allowed in tests.
|
||||||
|
- linters:
|
||||||
|
- forbidigo
|
||||||
|
text: should not be used because managedFields was removed
|
||||||
|
path: _test.go$
|
||||||
|
|
||||||
linters:
|
linters:
|
||||||
disable-all: true # not disabled in golangci-strict.yaml
|
disable-all: true # not disabled in golangci-strict.yaml
|
||||||
enable: # please keep this alphabetized and in sync with golangci-strict.yaml
|
enable: # please keep this alphabetized and in sync with golangci-strict.yaml
|
||||||
|
- forbidigo
|
||||||
- ginkgolinter
|
- ginkgolinter
|
||||||
- gocritic
|
- gocritic
|
||||||
- govet
|
- govet
|
||||||
@ -46,6 +52,15 @@ linters-settings: # please keep this alphabetized
|
|||||||
path: ../_output/local/bin/logcheck.so
|
path: ../_output/local/bin/logcheck.so
|
||||||
description: structured logging checker
|
description: structured logging checker
|
||||||
original-url: k8s.io/logtools/logcheck
|
original-url: k8s.io/logtools/logcheck
|
||||||
|
forbidigo:
|
||||||
|
analyze-types: true
|
||||||
|
forbid:
|
||||||
|
- p: ^managedfields\.ExtractInto$
|
||||||
|
pkg: ^k8s\.io/apimachinery/pkg/util/managedfields$
|
||||||
|
msg: should not be used because managedFields was removed
|
||||||
|
- p: \.Extract
|
||||||
|
pkg: ^k8s\.io/client-go/applyconfigurations/
|
||||||
|
msg: should not be used because managedFields was removed
|
||||||
gocritic:
|
gocritic:
|
||||||
enabled-checks: # not limited in golangci-strict.yaml
|
enabled-checks: # not limited in golangci-strict.yaml
|
||||||
- equalFold # not limited in golangci-strict.yaml
|
- equalFold # not limited in golangci-strict.yaml
|
||||||
|
@ -125,7 +125,7 @@ func (e *extractor) extractUnstructured(object *unstructured.Unstructured, field
|
|||||||
return nil, fmt.Errorf("failed to fetch the objectType: %v", err)
|
return nil, fmt.Errorf("failed to fetch the objectType: %v", err)
|
||||||
}
|
}
|
||||||
result := &unstructured.Unstructured{}
|
result := &unstructured.Unstructured{}
|
||||||
err = managedfields.ExtractInto(object, *objectType, fieldManager, result, subresource)
|
err = managedfields.ExtractInto(object, *objectType, fieldManager, result, subresource) //nolint:forbidigo
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed calling ExtractInto for unstructured: %v", err)
|
return nil, fmt.Errorf("failed calling ExtractInto for unstructured: %v", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user