Skip to content

Commit

Permalink
analyzer: cleanup unused params (istio#43764)
Browse files Browse the repository at this point in the history
* analyzer: cleanup unused params

This is never used / always true

* cleanup

* lint

* fmt
  • Loading branch information
howardjohn authored Mar 6, 2023
1 parent 4cec869 commit 6216aa0
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 39 deletions.
2 changes: 1 addition & 1 deletion istioctl/cmd/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func Analyze() *cobra.Command {

sa := local.NewIstiodAnalyzer(analyzers.AllCombined(),
resource.Namespace(selectedNamespace),
resource.Namespace(istioNamespace), nil, true)
resource.Namespace(istioNamespace), nil)

// Check for suppressions and add them to our SourceAnalyzer
suppressions := make([]local.AnalysisSuppression, 0, len(suppress))
Expand Down
8 changes: 6 additions & 2 deletions istioctl/cmd/precheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,12 @@ func checkControlPlane(cli kube.CLIClient) (diag.Messages, error) {

// TODO: add more checks

sa := local.NewSourceAnalyzer(analysis.Combine("upgrade precheck", &maturity.AlphaAnalyzer{}),
resource.Namespace(selectedNamespace), resource.Namespace(istioNamespace), nil, true, analysisTimeout)
sa := local.NewSourceAnalyzer(
analysis.Combine("upgrade precheck", &maturity.AlphaAnalyzer{}),
resource.Namespace(selectedNamespace),
resource.Namespace(istioNamespace),
nil,
)
// Set up the kube client
config := kube.BuildClientCmd(kubeconfig, configContext)
restConfig, err := config.ClientConfig()
Expand Down
3 changes: 1 addition & 2 deletions istioctl/cmd/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,7 @@ func setTag(ctx context.Context, kubeClient kube.CLIClient, tagName, revision, i
}

func analyzeWebhook(name, wh, revision string, config *rest.Config) error {
sa := local.NewSourceAnalyzer(analysis.Combine("webhook", &webhook.Analyzer{}),
resource.Namespace(selectedNamespace), resource.Namespace(istioNamespace), nil, true, analysisTimeout)
sa := local.NewSourceAnalyzer(analysis.Combine("webhook", &webhook.Analyzer{}), resource.Namespace(selectedNamespace), resource.Namespace(istioNamespace), nil)
if err := sa.AddReaderKubeSource([]local.ReaderSource{{Name: "", Reader: strings.NewReader(wh)}}); err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions operator/pkg/helmreconciler/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,8 +522,7 @@ func (h *HelmReconciler) analyzeWebhooks(whs []string) error {

sa := local.NewSourceAnalyzer(analysis.Combine("webhook", &webhook.Analyzer{
SkipServiceCheck: true,
}),
resource.Namespace(h.iop.Spec.GetNamespace()), resource.Namespace(istioV1Alpha1.Namespace(h.iop.Spec)), nil, true, 30*time.Second)
}), resource.Namespace(h.iop.Spec.GetNamespace()), resource.Namespace(istioV1Alpha1.Namespace(h.iop.Spec)), nil)
var localWebhookYAMLReaders []local.ReaderSource
var parsedK8sObjects object.K8sObjects
for _, wh := range whs {
Expand Down
3 changes: 1 addition & 2 deletions pkg/config/analysis/analyzers/analyzers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"regexp"
"strings"
"testing"
"time"

. "github.com/onsi/gomega"

Expand Down Expand Up @@ -899,7 +898,7 @@ func TestAnalyzersHaveDescription(t *testing.T) {
}

func setupAnalyzerForCase(tc testCase, cr local.CollectionReporterFn) (*local.IstiodAnalyzer, error) {
sa := local.NewSourceAnalyzer(analysis.Combine("testCase", tc.analyzer), "", "istio-system", cr, true, 10*time.Second)
sa := local.NewSourceAnalyzer(analysis.Combine("testCase", tc.analyzer), "", "istio-system", cr)

// If a mesh config file is specified, use it instead of the defaults
if tc.meshConfigFile != "" {
Expand Down
3 changes: 1 addition & 2 deletions pkg/config/analysis/incluster/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ type Controller struct {
func NewController(stop <-chan struct{}, rwConfigStore model.ConfigStoreController,
kubeClient kube.Client, revision, namespace string, statusManager *status.Manager, domainSuffix string,
) (*Controller, error) {
ia := local.NewIstiodAnalyzer(analyzers.AllCombined(),
"", resource.Namespace(namespace), func(name config.GroupVersionKind) {}, true)
ia := local.NewIstiodAnalyzer(analyzers.AllCombined(), "", resource.Namespace(namespace), func(name config.GroupVersionKind) {})
ia.AddSource(rwConfigStore)
// Filter out configs watched by rwConfigStore so we don't watch multiple times
store, err := crdclient.NewForSchemas(kubeClient,
Expand Down
20 changes: 9 additions & 11 deletions pkg/config/analysis/local/analyze_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"os"
"strings"
"testing"
"time"

. "github.com/onsi/gomega"
v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -57,7 +56,6 @@ spec:
n1_i1: v1
`
blankCombinedAnalyzer = analysis.Combine("testCombined", blankTestAnalyzer)
timeout = 1 * time.Second
)

// Metadata implements Analyzer
Expand All @@ -78,7 +76,7 @@ func TestAbortWithNoSources(t *testing.T) {

cancel := make(chan struct{})

sa := NewSourceAnalyzer(blankCombinedAnalyzer, "", "", nil, false, timeout)
sa := NewSourceAnalyzer(blankCombinedAnalyzer, "", "", nil)
_, err := sa.Analyze(cancel)
g.Expect(err).To(Not(BeNil()))
}
Expand All @@ -102,7 +100,7 @@ func TestAnalyzersRun(t *testing.T) {
collectionAccessed = col
}

sa := NewSourceAnalyzer(analysis.Combine("a", a), "", "", cr, false, timeout)
sa := NewSourceAnalyzer(analysis.Combine("a", a), "", "", cr)
err := sa.AddReaderKubeSource(nil)
g.Expect(err).To(BeNil())

Expand All @@ -129,7 +127,7 @@ func TestFilterOutputByNamespace(t *testing.T) {
},
}

sa := NewSourceAnalyzer(analysis.Combine("a", a), "ns1", "", nil, false, timeout)
sa := NewSourceAnalyzer(analysis.Combine("a", a), "ns1", "", nil)
err := sa.AddReaderKubeSource(nil)
g.Expect(err).To(BeNil())

Expand All @@ -141,7 +139,7 @@ func TestFilterOutputByNamespace(t *testing.T) {
func TestAddInMemorySource(t *testing.T) {
g := NewWithT(t)

sa := NewSourceAnalyzer(blankCombinedAnalyzer, "", "", nil, false, timeout)
sa := NewSourceAnalyzer(blankCombinedAnalyzer, "", "", nil)

src := model.NewFakeStore()
sa.AddSource(dfCache{ConfigStore: src})
Expand All @@ -155,7 +153,7 @@ func TestAddRunningKubeSource(t *testing.T) {

mk := kube.NewFakeClient()

sa := NewSourceAnalyzer(blankCombinedAnalyzer, "", "", nil, false, timeout)
sa := NewSourceAnalyzer(blankCombinedAnalyzer, "", "", nil)

sa.AddRunningKubeSource(mk)
assert.Equal(t, sa.meshCfg, mesh.DefaultMeshConfig()) // Base default meshcfg
Expand Down Expand Up @@ -185,7 +183,7 @@ func TestAddRunningKubeSourceWithIstioMeshConfigMap(t *testing.T) {
t.Fatalf("Error creating mesh config configmap: %v", err)
}

sa := NewSourceAnalyzer(blankCombinedAnalyzer, "", istioNamespace, nil, false, timeout)
sa := NewSourceAnalyzer(blankCombinedAnalyzer, "", istioNamespace, nil)

sa.AddRunningKubeSource(mk)
g.Expect(sa.meshCfg.RootNamespace).To(Equal(testRootNamespace))
Expand All @@ -196,7 +194,7 @@ func TestAddRunningKubeSourceWithIstioMeshConfigMap(t *testing.T) {
func TestAddReaderKubeSource(t *testing.T) {
g := NewWithT(t)

sa := NewSourceAnalyzer(blankCombinedAnalyzer, "", "", nil, false, timeout)
sa := NewSourceAnalyzer(blankCombinedAnalyzer, "", "", nil)

tmpfile := tempFileFromString(t, YamlN1I1V1)
defer os.Remove(tmpfile.Name())
Expand All @@ -219,7 +217,7 @@ func TestAddReaderKubeSource(t *testing.T) {
func TestAddReaderKubeSourceSkipsBadEntries(t *testing.T) {
g := NewWithT(t)

sa := NewSourceAnalyzer(blankCombinedAnalyzer, "", "", nil, false, timeout)
sa := NewSourceAnalyzer(blankCombinedAnalyzer, "", "", nil)

tmpfile := tempFileFromString(t, JoinString(YamlN1I1V1, "bogus resource entry\n"))
defer func() { _ = os.Remove(tmpfile.Name()) }()
Expand Down Expand Up @@ -257,7 +255,7 @@ func JoinString(parts ...string) string {
func TestDefaultResourcesRespectsMeshConfig(t *testing.T) {
g := NewWithT(t)

sa := NewSourceAnalyzer(blankCombinedAnalyzer, "", "", nil, false, timeout)
sa := NewSourceAnalyzer(blankCombinedAnalyzer, "", "", nil)

// With ingress off, we shouldn't generate any default resources
ingressOffMeshCfg := tempFileFromString(t, "ingressControllerMode: 'OFF'")
Expand Down
12 changes: 4 additions & 8 deletions pkg/config/analysis/local/istiod_analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"io"
"os"
"strings"
"time"

"github.com/hashicorp/go-multierror"
"github.com/ryanuber/go-glob"
Expand Down Expand Up @@ -85,17 +84,15 @@ type IstiodAnalyzer struct {
}

// NewSourceAnalyzer is a drop-in replacement for the galley function, adapting to istiod analyzer.
func NewSourceAnalyzer(analyzer *analysis.CombinedAnalyzer, namespace, istioNamespace resource.Namespace,
cr CollectionReporterFn, serviceDiscovery bool, _ time.Duration,
) *IstiodAnalyzer {
return NewIstiodAnalyzer(analyzer, namespace, istioNamespace, cr, serviceDiscovery)
func NewSourceAnalyzer(analyzer *analysis.CombinedAnalyzer, namespace, istioNamespace resource.Namespace, cr CollectionReporterFn) *IstiodAnalyzer {
return NewIstiodAnalyzer(analyzer, namespace, istioNamespace, cr)
}

// NewIstiodAnalyzer creates a new IstiodAnalyzer with no sources. Use the Add*Source
// methods to add sources in ascending precedence order,
// then execute Analyze to perform the analysis
func NewIstiodAnalyzer(analyzer *analysis.CombinedAnalyzer, namespace,
istioNamespace resource.Namespace, cr CollectionReporterFn, serviceDiscovery bool,
istioNamespace resource.Namespace, cr CollectionReporterFn,
) *IstiodAnalyzer {
// collectionReporter hook function defaults to no-op
if cr == nil {
Expand All @@ -105,8 +102,7 @@ func NewIstiodAnalyzer(analyzer *analysis.CombinedAnalyzer, namespace,
// Get the closure of all input collections for our analyzer, paying attention to transforms
kubeResources := kuberesource.SkipExcludedCollections(
analyzer.Metadata().Inputs,
kuberesource.DefaultExcludedResourceKinds(),
serviceDiscovery)
kuberesource.DefaultExcludedResourceKinds())

mcfg := mesh.DefaultMeshConfig()
sa := &IstiodAnalyzer{
Expand Down
10 changes: 4 additions & 6 deletions pkg/config/legacy/util/kuberesource/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"istio.io/istio/pkg/config/schema/resource"
)

func SkipExcludedCollections(requiredCols []config.GroupVersionKind, excludedResourceKinds []string, enableServiceDiscovery bool) collection.Schemas {
func SkipExcludedCollections(requiredCols []config.GroupVersionKind, excludedResourceKinds []string) collection.Schemas {
resultBuilder := collection.NewSchemasBuilder()
for _, gv := range requiredCols {
s, f := collections.All.FindByGroupVersionKind(gv)
Expand All @@ -36,11 +36,9 @@ func SkipExcludedCollections(requiredCols []config.GroupVersionKind, excludedRes
disabled = true

// Check and see if this is needed for Service Discovery. If needed, we will need to re-enable.
if enableServiceDiscovery {
if IsRequiredForServiceDiscovery(s) {
// This is needed for service discovery. Re-enable.
disabled = false
}
if IsRequiredForServiceDiscovery(s) {
// This is needed for service discovery. Re-enable.
disabled = false
}
}

Expand Down
3 changes: 1 addition & 2 deletions tests/fuzz/analyzer_fuzzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package fuzz
import (
"bytes"
"os"
"time"

fuzz "github.com/AdaLogics/go-fuzz-headers"

Expand Down Expand Up @@ -141,7 +140,7 @@ func FuzzAnalyzer(data []byte) int {
return 0
}

sa := local.NewSourceAnalyzer(analysis.Combine("testCase", analyzer), "", "istio-system", cr, true, 10*time.Second)
sa := local.NewSourceAnalyzer(analysis.Combine("testCase", analyzer), "", "istio-system", cr)
if addMeshConfig {
err = sa.AddFileKubeMeshConfig(meshConfigFile)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion tools/bug-report/pkg/content/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func GetNetstat(p *Params) (map[string]string, error) {
// GetAnalyze returns the output of istioctl analyze.
func GetAnalyze(p *Params, timeout time.Duration) (map[string]string, error) {
out := make(map[string]string)
sa := local.NewSourceAnalyzer(analyzers.AllCombined(), resource.Namespace(p.Namespace), resource.Namespace(p.IstioNamespace), nil, true, timeout)
sa := local.NewSourceAnalyzer(analyzers.AllCombined(), resource.Namespace(p.Namespace), resource.Namespace(p.IstioNamespace), nil)

k, err := kube.NewClient(kube.NewClientConfigForRestConfig(p.Runner.Client.RESTConfig()))
if err != nil {
Expand Down

0 comments on commit 6216aa0

Please sign in to comment.