Skip to content

Commit eafdb1d

Browse files
ozevrenistio-merge-robot
authored andcommitted
Cleanup linter issues in Mixer (istio#1826)
Automatic merge from submit-queue. Cleanup linter issues in Mixer **What this PR does / why we need it**: Cleans up most of the linter issues in Mixer. **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes # **Special notes for your reviewer**: **Release note**: ```release-note NONE ```
1 parent bd88b62 commit eafdb1d

File tree

20 files changed

+54
-47
lines changed

20 files changed

+54
-47
lines changed

mixer/adapter/svcctrl/reportbuilder_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ func TestGenerateLogErrorCause(t *testing.T) {
228228

229229
func TestNewReportBuilder(t *testing.T) {
230230
instance := new(svcctrlreport.Instance)
231-
supportedMetrics := []metricDef{
231+
metrics := []metricDef{
232232
{
233233
name: "test_metric",
234234
valueGenerator: generateRequestCount,
@@ -238,9 +238,9 @@ func TestNewReportBuilder(t *testing.T) {
238238
},
239239
}
240240
resolver := new(mockConsumerProjectIDResolver)
241-
builder := newReportBuilder(instance, supportedMetrics, resolver)
241+
builder := newReportBuilder(instance, metrics, resolver)
242242
expectedBuilder := reportBuilder{
243-
supportedMetrics,
243+
metrics,
244244
instance,
245245
resolver,
246246
}

mixer/adapter/svcctrl/reportprocessor_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ func TestNewReportProcessor(t *testing.T) {
222222
env: at.NewEnv(t),
223223
client: new(mockSvcctrlClient),
224224
serviceConfigIndex: map[string]*config.GcpServiceSetting{
225-
"echo": &config.GcpServiceSetting{
225+
"echo": {
226226
MeshServiceName: "echo",
227227
GoogleServiceName: "echo.googleapi.com",
228228
},

mixer/adapter/svcctrl/svcctrl.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ func (b *builder) Validate() *adapter.ConfigErrors {
7777
func validateRuntimeConfig(config *config.RuntimeConfig) *multierror.Error {
7878
var result *multierror.Error
7979
if config == nil {
80-
result = multierror.Append(result, errors.New("RuntimeConfig is nil"))
80+
result = multierror.Append(result, errors.New("config is nil"))
8181
return result
8282
}
8383

8484
if config.CheckResultExpiration == nil {
85-
result = multierror.Append(result, errors.New("RuntimeConfig.CheckResultExpiration is nil"))
85+
result = multierror.Append(result, errors.New("config.CheckResultExpiration is nil"))
8686
return result
8787
}
8888
exp, err := pbtypes.DurationFromProto(config.CheckResultExpiration)
@@ -99,19 +99,19 @@ func validateRuntimeConfig(config *config.RuntimeConfig) *multierror.Error {
9999
func validateGcpServiceSetting(settings []*config.GcpServiceSetting) *multierror.Error {
100100
var result *multierror.Error
101101
if settings == nil || len(settings) == 0 {
102-
result = multierror.Append(result, errors.New("ServiceConfigs is nil or empty"))
102+
result = multierror.Append(result, errors.New("settings is nil or empty"))
103103
return result
104104
}
105105
for _, setting := range settings {
106106
if setting.MeshServiceName == "" || setting.GoogleServiceName == "" {
107107
result = multierror.Append(result,
108-
errors.New("MeshServiceName and GoogleServiceName must be non-empty"))
108+
errors.New("settings.MeshServiceName and settings.GoogleServiceName must be non-empty"))
109109
}
110110

111111
if setting.Quotas != nil {
112112
for _, qCfg := range setting.Quotas {
113113
if qCfg.Name == "" {
114-
result = multierror.Append(result, errors.New("QuotaName is empty"))
114+
result = multierror.Append(result, errors.New("encountered an empty QuotaName"))
115115
}
116116
if qCfg.Expiration == nil {
117117
result = multierror.Append(result, errors.New("quota expiration is nil"))
@@ -122,7 +122,7 @@ func validateGcpServiceSetting(settings []*config.GcpServiceSetting) *multierror
122122
} else if expiration <= 0 {
123123
result = multierror.Append(
124124
result, fmt.Errorf(
125-
`quota must have postive expiration, but get %v`, expiration))
125+
`quota must have positive expiration, but get %v`, expiration))
126126
}
127127
}
128128
}

mixer/cmd/server/cmd/validator.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ func validatorCmd(info map[string]template.Info, adapters []adapter.InfoFn, prin
5555
"the list of namespaces where changes should be validated. Empty means to validate everything. Used for test only.")
5656
validatorCmd.PersistentFlags().IntVarP(&vc.Port, "port", "p", 9099, "the port number of the webhook")
5757
validatorCmd.PersistentFlags().StringVar(&vc.SecretName, "secret-name", "", "The name of k8s secret where the certificates are stored")
58-
validatorCmd.PersistentFlags().DurationVar(&vc.RegistrationDelay, "registration-delay", 5*time.Second, "Time to delay webhook registration after starting webhook server")
58+
validatorCmd.PersistentFlags().DurationVar(&vc.RegistrationDelay, "registration-delay", 5*time.Second,
59+
"Time to delay webhook registration after starting webhook server")
5960
validatorCmd.PersistentFlags().StringVar(&kubeconfig, "kubeconfig", "", "Use a Kubernetes configuration file instead of in-cluster configuration")
6061
return validatorCmd
6162
}

mixer/pkg/adapter/test/env.go

+1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ func (e *Env) log(format string, args ...interface{}) string {
9898
return l
9999
}
100100

101+
// GetDoneChan returns the channel that returns notification when the async work is done.
101102
func (e *Env) GetDoneChan() chan struct{} {
102103
return e.done
103104
}

mixer/pkg/cache/cache.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
// The cache package provides general-purpose in-memory caches.
15+
// Package cache provides general-purpose in-memory caches.
1616
// Different caches provide different eviction policies suitable for
1717
// specific use cases.
1818
package cache

mixer/pkg/cache/cache_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func testCacheBasic(c Cache, t *testing.T) {
8888
}
8989
} else {
9090
if value != nil {
91-
t.Error("Got value %v, expected nil", value)
91+
t.Errorf("Got value %v, expected nil", value)
9292
}
9393
}
9494

mixer/pkg/cache/lruCache.go

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14+
1415
package cache
1516

1617
import (

mixer/pkg/cache/ttlCache.go

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14+
1415
package cache
1516

1617
import (

mixer/pkg/config/crd/BUILD

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ go_test(
4242
],
4343
library = ":go_default_library",
4444
deps = [
45-
"//pilot/platform/kube/admit/testcerts:go_default_library", # for testing cert data
4645
"//mixer/pkg/config/store:go_default_library",
46+
"//pilot/platform/kube/admit/testcerts:go_default_library", # for testing cert data
4747
"@io_k8s_apimachinery//pkg/apis/meta/v1:go_default_library",
4848
"@io_k8s_apimachinery//pkg/apis/meta/v1/unstructured:go_default_library",
4949
"@io_k8s_apimachinery//pkg/runtime:go_default_library",

mixer/pkg/config/manager_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func TestConfigManager(t *testing.T) {
100100
func TestManager_FetchError(t *testing.T) {
101101
errStr := "TestManager_FetchError"
102102
store := newFakeStore("{}", "{}")
103-
mgr := NewManager(nil, nil,nil, nil, nil, nil,
103+
mgr := NewManager(nil, nil, nil, nil, nil, nil,
104104
template.NewRepository(nil), store, loopDelay, keyTargetService, keyServiceDomain)
105105

106106
mgr.validate = func(cfg map[string]string) (rt *Validated, desc descriptor.Finder, ce *adapter.ConfigErrors) {

mixer/pkg/config/validator.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -790,8 +790,8 @@ func convertInstanceParam(tf template.Repository, templateName string, params in
790790
}
791791

792792
// convertAspectParams converts returns a typed proto message based on available validator.
793-
func convertAspectParams(
794-
f AspectValidatorFinder, name string, params interface{}, strict bool, df descriptor.Finder, typeChecker expr.TypeChecker) (AspectParams, *adapter.ConfigErrors) {
793+
func convertAspectParams(f AspectValidatorFinder, name string, params interface{}, strict bool, df descriptor.Finder,
794+
typeChecker expr.TypeChecker) (AspectParams, *adapter.ConfigErrors) {
795795

796796
var ce *adapter.ConfigErrors
797797
var avl AspectValidator

mixer/pkg/il/b/a/a.txt

Whitespace-only changes.

mixer/pkg/il/evaluator/checker.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ func (c *checker) EvalType(expression string, attrFinder expr.AttributeDescripto
3535
return v.EvalType(attrFinder, c.functions)
3636
}
3737

38-
func (e *checker) AssertType(expression string, finder expr.AttributeDescriptorFinder, expectedType dpb.ValueType) error {
39-
if t, err := e.EvalType(expression, finder); err != nil {
38+
func (c *checker) AssertType(expression string, finder expr.AttributeDescriptorFinder, expectedType dpb.ValueType) error {
39+
if t, err := c.EvalType(expression, finder); err != nil {
4040
return err
4141
} else if t != expectedType {
4242
return fmt.Errorf("expression '%s' evaluated to type %v, expected type %v", expression, t, expectedType)

mixer/pkg/il/runtime/externs.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@ import (
2727

2828
// Externs contains the list of standard external functions used during evaluation.
2929
var Externs = map[string]interpreter.Extern{
30-
"ip": interpreter.ExternFromFn("ip", externIp),
31-
"ip_equal": interpreter.ExternFromFn("ip_equal", externIpEqual),
30+
"ip": interpreter.ExternFromFn("ip", externIP),
31+
"ip_equal": interpreter.ExternFromFn("ip_equal", externIPEqual),
3232
"timestamp": interpreter.ExternFromFn("timestamp", externTimestamp),
3333
"timestamp_equal": interpreter.ExternFromFn("timestamp_equal", externTimestampEqual),
3434
"match": interpreter.ExternFromFn("match", externMatch),
3535
}
3636

37+
// ExternFunctionMetadata is the type-metadata about externs. It gets used during compilations.
3738
var ExternFunctionMetadata = []expr.FunctionMetadata{
3839
{
3940
Name: "ip",
@@ -52,14 +53,14 @@ var ExternFunctionMetadata = []expr.FunctionMetadata{
5253
},
5354
}
5455

55-
func externIp(in string) ([]byte, error) {
56+
func externIP(in string) ([]byte, error) {
5657
if ip := net.ParseIP(in); ip != nil {
5758
return []byte(ip), nil
5859
}
5960
return []byte{}, fmt.Errorf("could not convert %s to IP_ADDRESS", in)
6061
}
6162

62-
func externIpEqual(a []byte, b []byte) bool {
63+
func externIPEqual(a []byte, b []byte) bool {
6364
// net.IP is an alias for []byte, so these are safe to convert
6465
ip1 := net.IP(a)
6566
ip2 := net.IP(b)

mixer/pkg/il/runtime/externs_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
)
2323

2424
func TestExternIp(t *testing.T) {
25-
b, err := externIp("1.2.3.4")
25+
b, err := externIP("1.2.3.4")
2626
if err != nil {
2727
t.Fatalf("Unexpected error: %v", err)
2828
}
@@ -32,21 +32,21 @@ func TestExternIp(t *testing.T) {
3232
}
3333

3434
func TestExternIp_Error(t *testing.T) {
35-
_, err := externIp("A.A.A.A")
35+
_, err := externIP("A.A.A.A")
3636
if err == nil {
3737
t.Fatalf("Expected error not found.")
3838
}
3939
}
4040

4141
func TestExternIpEqual_True(t *testing.T) {
42-
b := externIpEqual(net.ParseIP("1.2.3.4"), net.ParseIP("1.2.3.4"))
42+
b := externIPEqual(net.ParseIP("1.2.3.4"), net.ParseIP("1.2.3.4"))
4343
if !b {
4444
t.Fatal()
4545
}
4646
}
4747

4848
func TestExternIpEqual_False(t *testing.T) {
49-
b := externIpEqual(net.ParseIP("1.2.3.4"), net.ParseIP("1.2.3.5"))
49+
b := externIPEqual(net.ParseIP("1.2.3.4"), net.ParseIP("1.2.3.5"))
5050
if b {
5151
t.Fatal()
5252
}

mixer/pkg/il/testing/tests.go

+12-11
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ var time1977 = time.Date(1977, time.February, 4, 12, 00, 0, 0, time.UTC)
2929
var t, _ = time.Parse(time.RFC3339, "2015-01-02T15:04:35Z")
3030
var t2, _ = time.Parse(time.RFC3339, "2015-01-02T15:04:34Z")
3131

32+
// TestData contains the common set of tests that is used by various components of il.
3233
var TestData = []TestInfo{
3334

3435
// Tests from expr/eval_test.go TestGoodEval
@@ -1465,7 +1466,7 @@ end`,
14651466
},
14661467

14671468
{
1468-
E: `"foo" | "bar"`,
1469+
E: `"foo" | "bar"`,
14691470
IL: `
14701471
fn eval() string
14711472
apush_s "foo"
@@ -1479,7 +1480,7 @@ end
14791480
},
14801481

14811482
{
1482-
E: `ip("1.2.3.4")`,
1483+
E: `ip("1.2.3.4")`,
14831484
IL: `
14841485
fn eval() interface
14851486
apush_s "1.2.3.4"
@@ -1491,8 +1492,8 @@ end
14911492
},
14921493

14931494
{
1494-
E: `ip(as)`,
1495-
I: map[string]interface{} {
1495+
E: `ip(as)`,
1496+
I: map[string]interface{}{
14961497
"as": "1.2.3.4",
14971498
},
14981499
IL: `
@@ -1506,7 +1507,7 @@ end
15061507
},
15071508

15081509
{
1509-
E: `ip("1.2.3.4" | "5.6.7.8")`,
1510+
E: `ip("1.2.3.4" | "5.6.7.8")`,
15101511
IL: `
15111512
fn eval() interface
15121513
apush_s "1.2.3.4"
@@ -1521,7 +1522,7 @@ end
15211522
},
15221523

15231524
{
1524-
E: `ip(as | "5.6.7.8")`,
1525+
E: `ip(as | "5.6.7.8")`,
15251526
IL: `
15261527
fn eval() interface
15271528
tresolve_s "as"
@@ -1536,23 +1537,23 @@ end
15361537
},
15371538

15381539
{
1539-
E: `ip(as | bs)`,
1540-
I: map[string]interface{} {
1540+
E: `ip(as | bs)`,
1541+
I: map[string]interface{}{
15411542
"bs": "1.2.3.4",
15421543
},
15431544
R: []uint8(net.ParseIP("1.2.3.4")),
15441545
},
15451546

15461547
{
1547-
E: `ip(as | bs)`,
1548+
E: `ip(as | bs)`,
15481549
Err: "lookup failed: 'bs'",
15491550
},
15501551

15511552
{
15521553
E: `ip(ar["foo"])`,
15531554
IL: ``,
1554-
I: map[string]interface{} {
1555-
"ar": map[string]string{ "foo": "1.2.3.4" },
1555+
I: map[string]interface{}{
1556+
"ar": map[string]string{"foo": "1.2.3.4"},
15561557
},
15571558
R: []uint8(net.ParseIP("1.2.3.4")),
15581559
},

mixer/pkg/il/testing/util.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ func AreEqual(e interface{}, a interface{}) bool {
2323
if eb, ok := e.([]byte); ok {
2424
if ab, ok := a.([]byte); ok {
2525
return bytes.Equal(ab, eb)
26-
} else {
27-
return false
2826
}
27+
28+
return false
2929
}
3030

3131
return a == e

mixer/pkg/mock/server.go

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"istio.io/istio/mixer/pkg/template"
2828
)
2929

30+
// Server is an in-memory Mixer service.
3031
type Server struct {
3132
addr string
3233
mixerContext *cmd.ServerContext

mixer/tools/codegen/pkg/interfacegen/generator.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ import (
3232
)
3333

3434
const (
35-
ResourceMsgTypeSuffix = "Type"
36-
ResourceMsgInstParamSuffix = "InstanceParam"
35+
resourceMsgTypeSuffix = "Type"
36+
resourceMsgInstParamSuffix = "InstanceParam"
3737
fullGoNameOfValueTypeEnum = "istio_mixer_v1_config_descriptor.ValueType"
3838
goFileImportFmt = `"%s"`
3939
protoFileImportFmt = `import "%s";`
@@ -169,7 +169,7 @@ func stringify(protoType modelgen.TypeInfo) string {
169169
return toProtoMap(stringify(*protoType.MapKey), stringify(*protoType.MapValue))
170170
}
171171
if protoType.IsResourceMessage {
172-
return protoType.Name + ResourceMsgInstParamSuffix
172+
return protoType.Name + resourceMsgInstParamSuffix
173173
}
174174
return "string"
175175
}
@@ -182,10 +182,10 @@ func (g *Generator) getAugmentedProtoContent(model *modelgen.Model) ([]byte, err
182182
"valueTypeOrResMsg": valueTypeOrResMsg,
183183
"valueTypeOrResMsgFieldTypeName": func(protoTypeInfo modelgen.TypeInfo) string {
184184
if protoTypeInfo.IsResourceMessage {
185-
return protoTypeInfo.Name + ResourceMsgTypeSuffix
185+
return protoTypeInfo.Name + resourceMsgTypeSuffix
186186
}
187187
if protoTypeInfo.IsMap && protoTypeInfo.MapValue.IsResourceMessage {
188-
return toProtoMap(protoTypeInfo.MapKey.Name, protoTypeInfo.MapValue.Name+ResourceMsgTypeSuffix)
188+
return toProtoMap(protoTypeInfo.MapKey.Name, protoTypeInfo.MapValue.Name+resourceMsgTypeSuffix)
189189
}
190190
return protoTypeInfo.Name
191191
},
@@ -203,10 +203,10 @@ func (g *Generator) getAugmentedProtoContent(model *modelgen.Model) ([]byte, err
203203
return ""
204204
},
205205
"getResourcMessageTypeName": func(s string) string {
206-
return s + ResourceMsgTypeSuffix
206+
return s + resourceMsgTypeSuffix
207207
},
208208
"getResourcMessageInterfaceParamTypeName": func(s string) string {
209-
return s + ResourceMsgInstParamSuffix
209+
return s + resourceMsgInstParamSuffix
210210
},
211211
},
212212
).Parse(tmpl.RevisedTemplateTmpl)

0 commit comments

Comments
 (0)