Skip to content

Commit

Permalink
add missing license headers, make linters happier
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Revin <[email protected]>
  • Loading branch information
nrvnrvn committed May 14, 2019
1 parent 139b49c commit 22ebf43
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 31 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,4 @@ Once the reconfiguration has been finished all `Pod`s are labeled appropriately

### Short term

- [] add more testing
- [ ] add more testing
38 changes: 26 additions & 12 deletions pkg/controller/redis/deepcontains_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2019 The redis-operator Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package redis

import (
Expand Down Expand Up @@ -44,7 +58,7 @@ func Test_deepContains(t *testing.T) {
Tinterface: basic,
Tpointer: &basic,
Tstruct: basic,
Tmap: map[basicStruct]basicStruct{basic: basic, basicStruct{Tstring: "o"}: basic},
Tmap: map[basicStruct]basicStruct{basic: basic, {Tstring: "o"}: basic},
}

f := func() {}
Expand Down Expand Up @@ -73,13 +87,13 @@ func Test_deepContains(t *testing.T) {
// composite
{"composite-empty", args{compositeStruct{}, compositeStruct{}}, true},
{"composite-equal", args{composite, composite}, true},
{"composite-Tarray-true", args{composite, compositeStruct{Tarray: [2]basicStruct{basicStruct{Tstring: "o"}, basicStruct{}}}}, true},
{"composite-Tslice-true", args{composite, compositeStruct{Tslice: []basicStruct{basicStruct{Tstring: "o"}}}}, true},
{"composite-Tinterface-true", args{composite, compositeStruct{Tslice: []basicStruct{basicStruct{Tstring: "o"}}}}, true},
{"composite-Tarray-true", args{composite, compositeStruct{Tarray: [2]basicStruct{{Tstring: "o"}, {}}}}, true},
{"composite-Tslice-true", args{composite, compositeStruct{Tslice: []basicStruct{{Tstring: "o"}}}}, true},
{"composite-Tinterface-true", args{composite, compositeStruct{Tslice: []basicStruct{{Tstring: "o"}}}}, true},
{"composite-Tstruct-true", args{composite, compositeStruct{Tstruct: basicStruct{Tstring: "o"}}}, true},
{"composite-Tpointer-true", args{composite, compositeStruct{Tpointer: &basicStruct{Tstring: "o"}}}, true},
{"composite-Tpointer-deep-true", args{compositeStruct{Tinterface: &[]basicStruct{basic}}, compositeStruct{Tinterface: &[]basicStruct{basic}}}, true},
{"composite-Tmap-true", args{composite, compositeStruct{Tmap: map[basicStruct]basicStruct{basic: basicStruct{Tstring: "o"}}}}, true},
{"composite-Tmap-true", args{composite, compositeStruct{Tmap: map[basicStruct]basicStruct{basic: {Tstring: "o"}}}}, true},

// negative tests
// basic
Expand All @@ -92,17 +106,17 @@ func Test_deepContains(t *testing.T) {
{"basic-Tuint-false", args{basic, basicStruct{Tuint: uint(2)}}, false},
{"basic-Tfloat32-false", args{basic, basicStruct{Tfloat32: math.E}}, false},
// composite
{"composite-Tarray-false", args{composite, compositeStruct{Tarray: [2]basicStruct{basicStruct{Tstring: "oo"}, basicStruct{}}}}, false},
{"composite-Tslice-false", args{composite, compositeStruct{Tslice: []basicStruct{basicStruct{Tstring: "oo"}, basicStruct{}, basicStruct{}, basicStruct{}}}}, false},
{"composite-Tinterface-false", args{composite, compositeStruct{Tslice: []basicStruct{basicStruct{Tstring: "oo"}}}}, false},
{"composite-Tarray-false", args{composite, compositeStruct{Tarray: [2]basicStruct{{Tstring: "oo"}, {}}}}, false},
{"composite-Tslice-false", args{composite, compositeStruct{Tslice: []basicStruct{{Tstring: "oo"}, {}, {}, {}}}}, false},
{"composite-Tinterface-false", args{composite, compositeStruct{Tslice: []basicStruct{{Tstring: "oo"}}}}, false},
{"composite-Tinterface-deepFunc-false", args{compositeStruct{Tinterface: f}, compositeStruct{Tinterface: f}}, false},
{"composite-Tstruct-false", args{composite, compositeStruct{Tstruct: basicStruct{Tstring: "oo"}}}, false},
{"composite-Tpointer-false", args{composite, compositeStruct{Tpointer: &basicStruct{Tstring: "oo"}}}, false},
{"composite-Tpointer-deep-false", args{compositeStruct{Tinterface: &[]basicStruct{basic}}, compositeStruct{Tinterface: &[]basicStruct{basicStruct{Tstring: "oo"}}}}, false},
{"composite-Tpointer-deep-false", args{compositeStruct{Tinterface: &[]basicStruct{basic}}, compositeStruct{Tinterface: &[]basicStruct{{Tstring: "oo"}}}}, false},
{"composite-Tpointer-deepType-false", args{compositeStruct{Tinterface: &[]basicStruct{basic}}, compositeStruct{Tinterface: &[]int{}}}, false},
{"composite-Tmap-falseValue", args{composite, compositeStruct{Tmap: map[basicStruct]basicStruct{basic: basicStruct{Tstring: "oo"}}}}, false},
{"composite-Tmap-falseKey", args{composite, compositeStruct{Tmap: map[basicStruct]basicStruct{basicStruct{}: basicStruct{Tstring: "o"}}}}, false},
{"composite-Tmap-falseLen", args{composite, compositeStruct{Tmap: map[basicStruct]basicStruct{basicStruct{Tstring: "o"}: basicStruct{}, basicStruct{Tstring: "oo"}: basicStruct{}, basicStruct{Tstring: "ooo"}: basicStruct{}}}}, false},
{"composite-Tmap-falseValue", args{composite, compositeStruct{Tmap: map[basicStruct]basicStruct{basic: {Tstring: "oo"}}}}, false},
{"composite-Tmap-falseKey", args{composite, compositeStruct{Tmap: map[basicStruct]basicStruct{{}: {Tstring: "o"}}}}, false},
{"composite-Tmap-falseLen", args{composite, compositeStruct{Tmap: map[basicStruct]basicStruct{{Tstring: "o"}: {}, {Tstring: "oo"}: {}, {Tstring: "ooo"}: {}}}}, false},
}

for _, tt := range tests {
Expand Down
38 changes: 26 additions & 12 deletions pkg/controller/redis/object_generator.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2019 The redis-operator Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package redis

import (
Expand Down Expand Up @@ -75,18 +89,18 @@ var (
// that are not supposed to be changed or those controlled by redis-operator.
// Sorted in order of appearance in https://github.com/antirez/redis/blob/5.0/redis.conf
excludedConfigDirectives = map[string]struct{}{
"include": struct{}{},
"bind": struct{}{},
"protected-mode": struct{}{},
"port": struct{}{},
"daemonize": struct{}{},
"dir": struct{}{},
"replica-announce-ip": struct{}{},
"replica-announce-port": struct{}{},
"replicaof": struct{}{},
"masterauth": struct{}{},
"requirepass": struct{}{},
"rename-command": struct{}{},
"include": {},
"bind": {},
"protected-mode": {},
"port": {},
"daemonize": {},
"dir": {},
"replica-announce-ip": {},
"replica-announce-port": {},
"replicaof": {},
"masterauth": {},
"requirepass": {},
"rename-command": {},
}
argonThreads = uint8(runtime.NumCPU())
)
Expand Down
14 changes: 14 additions & 0 deletions pkg/controller/redis/object_generator_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2019 The redis-operator Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package redis

import (
Expand Down
14 changes: 14 additions & 0 deletions pkg/controller/redis/redis_controller.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2019 The redis-operator Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package redis

import (
Expand Down
12 changes: 6 additions & 6 deletions pkg/redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,15 @@ type Redises []Redis
// sort.Interface implementation for Redises.
// Allows to choose an instance with a lesser priority and higher replication offset.
// Note that this assumes that Redises don't have replicas with ReplicaPriority == 0
func (a Redises) Len() int { return len(a) }
func (a Redises) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a Redises) Less(i, j int) bool {
func (instances Redises) Len() int { return len(instances) }
func (instances Redises) Swap(i, j int) { instances[i], instances[j] = instances[j], instances[i] }
func (instances Redises) Less(i, j int) bool {
// choose a replica with less replica priority
// choose a bigger replication offset otherwise
if a[i].ReplicaPriority == a[j].ReplicaPriority {
return a[i].ReplicationOffset > a[j].ReplicationOffset
if instances[i].ReplicaPriority == instances[j].ReplicaPriority {
return instances[i].ReplicationOffset > instances[j].ReplicationOffset
}
return a[i].ReplicaPriority < a[j].ReplicaPriority
return instances[i].ReplicaPriority < instances[j].ReplicaPriority
}

// strict implementation check
Expand Down

0 comments on commit 22ebf43

Please sign in to comment.