Skip to content

Commit ed8767c

Browse files
committed
fix golint errors for pkg/master, together with cheftako
1 parent 5fbda60 commit ed8767c

File tree

6 files changed

+45
-37
lines changed

6 files changed

+45
-37
lines changed

hack/.golint_failures

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ pkg/kubelet/status/testing
137137
pkg/kubelet/sysctl
138138
pkg/kubelet/types
139139
pkg/kubemark
140-
pkg/master
141140
pkg/master/controller/crdregistration
142141
pkg/master/tunneler
143142
pkg/proxy/apis/config

pkg/master/client_ca_hook.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
corev1client "k8s.io/client-go/kubernetes/typed/core/v1"
3232
)
3333

34+
// ClientCARegistrationHook defines CA registration hook request structure
3435
type ClientCARegistrationHook struct {
3536
ClientCA []byte
3637

@@ -41,6 +42,7 @@ type ClientCARegistrationHook struct {
4142
RequestHeaderAllowedNames []string
4243
}
4344

45+
// PostStartHook initializes client CA configmap for the API server
4446
func (h ClientCARegistrationHook) PostStartHook(hookContext genericapiserver.PostStartHookContext) error {
4547
// initializing CAs is important so that aggregated API servers can come up with "normal" config.
4648
// We've seen lagging etcd before, so we want to retry this a few times before we decide to crashloop

pkg/master/controller.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,13 @@ func (c *completedConfig) NewBootstrapController(legacyRESTStorage corerest.Lega
131131
}
132132
}
133133

134+
// PostStartHook initiates the core controller loops that must exist for bootstrapping.
134135
func (c *Controller) PostStartHook(hookContext genericapiserver.PostStartHookContext) error {
135136
c.Start()
136137
return nil
137138
}
138139

140+
// PreShutdownHook triggers the actions needed to shut down the API Server cleanly.
139141
func (c *Controller) PreShutdownHook() error {
140142
c.Stop()
141143
return nil
@@ -171,6 +173,7 @@ func (c *Controller) Start() {
171173
c.runner.Start()
172174
}
173175

176+
// Stop cleans up this API Servers endpoint reconciliation leases so another master can take over more quickly.
174177
func (c *Controller) Stop() {
175178
if c.runner != nil {
176179
c.runner.Stop()
@@ -279,7 +282,7 @@ func createEndpointPortSpec(endpointPort int, endpointPortName string, extraEndp
279282
return endpointPorts
280283
}
281284

282-
// CreateMasterServiceIfNeeded will create the specified service if it
285+
// CreateOrUpdateMasterServiceIfNeeded will create the specified service if it
283286
// doesn't already exist.
284287
func (c *Controller) CreateOrUpdateMasterServiceIfNeeded(serviceName string, serviceIP net.IP, servicePorts []corev1.ServicePort, serviceType corev1.ServiceType, reconcile bool) error {
285288
if s, err := c.ServiceClient.Services(metav1.NamespaceDefault).Get(serviceName, metav1.GetOptions{}); err == nil {

pkg/master/controller_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func TestReconcileEndpoints(t *testing.T) {
3434
om := func(name string) metav1.ObjectMeta {
3535
return metav1.ObjectMeta{Namespace: ns, Name: name}
3636
}
37-
reconcile_tests := []struct {
37+
reconcileTests := []struct {
3838
testName string
3939
serviceName string
4040
ip string
@@ -387,7 +387,7 @@ func TestReconcileEndpoints(t *testing.T) {
387387
},
388388
},
389389
}
390-
for _, test := range reconcile_tests {
390+
for _, test := range reconcileTests {
391391
fakeClient := fake.NewSimpleClientset()
392392
if test.endpoints != nil {
393393
fakeClient = fake.NewSimpleClientset(test.endpoints)
@@ -437,7 +437,7 @@ func TestReconcileEndpoints(t *testing.T) {
437437

438438
}
439439

440-
non_reconcile_tests := []struct {
440+
nonReconcileTests := []struct {
441441
testName string
442442
serviceName string
443443
ip string
@@ -506,7 +506,7 @@ func TestReconcileEndpoints(t *testing.T) {
506506
},
507507
},
508508
}
509-
for _, test := range non_reconcile_tests {
509+
for _, test := range nonReconcileTests {
510510
fakeClient := fake.NewSimpleClientset()
511511
if test.endpoints != nil {
512512
fakeClient = fake.NewSimpleClientset(test.endpoints)
@@ -564,7 +564,7 @@ func TestCreateOrUpdateMasterService(t *testing.T) {
564564
return metav1.ObjectMeta{Namespace: ns, Name: name}
565565
}
566566

567-
create_tests := []struct {
567+
createTests := []struct {
568568
testName string
569569
serviceName string
570570
servicePorts []corev1.ServicePort
@@ -592,7 +592,7 @@ func TestCreateOrUpdateMasterService(t *testing.T) {
592592
},
593593
},
594594
}
595-
for _, test := range create_tests {
595+
for _, test := range createTests {
596596
master := Controller{}
597597
fakeClient := fake.NewSimpleClientset()
598598
master.ServiceClient = fakeClient.CoreV1()
@@ -618,7 +618,7 @@ func TestCreateOrUpdateMasterService(t *testing.T) {
618618
}
619619
}
620620

621-
reconcile_tests := []struct {
621+
reconcileTests := []struct {
622622
testName string
623623
serviceName string
624624
servicePorts []corev1.ServicePort
@@ -874,7 +874,7 @@ func TestCreateOrUpdateMasterService(t *testing.T) {
874874
expectUpdate: nil,
875875
},
876876
}
877-
for _, test := range reconcile_tests {
877+
for _, test := range reconcileTests {
878878
master := Controller{}
879879
fakeClient := fake.NewSimpleClientset(test.service)
880880
master.ServiceClient = fakeClient.CoreV1()
@@ -903,7 +903,7 @@ func TestCreateOrUpdateMasterService(t *testing.T) {
903903
}
904904
}
905905

906-
non_reconcile_tests := []struct {
906+
nonReconcileTests := []struct {
907907
testName string
908908
serviceName string
909909
servicePorts []corev1.ServicePort
@@ -933,7 +933,7 @@ func TestCreateOrUpdateMasterService(t *testing.T) {
933933
expectUpdate: nil,
934934
},
935935
}
936-
for _, test := range non_reconcile_tests {
936+
for _, test := range nonReconcileTests {
937937
master := Controller{}
938938
fakeClient := fake.NewSimpleClientset(test.service)
939939
master.ServiceClient = fakeClient.CoreV1()

pkg/master/import_known_versions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ limitations under the License.
1616

1717
package master
1818

19-
// These imports are the API groups the API server will support.
2019
import (
20+
// These imports are the API groups the API server will support.
2121
_ "k8s.io/kubernetes/pkg/apis/admission/install"
2222
_ "k8s.io/kubernetes/pkg/apis/admissionregistration/install"
2323
_ "k8s.io/kubernetes/pkg/apis/apps/install"

pkg/master/master.go

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ const (
118118
DefaultEndpointReconcilerTTL = 15 * time.Second
119119
)
120120

121+
// ExtraConfig defines extra configuration for the master
121122
type ExtraConfig struct {
122123
ClientCARegistrationHook ClientCARegistrationHook
123124

@@ -189,6 +190,7 @@ type ExtraConfig struct {
189190
VersionedInformers informers.SharedInformerFactory
190191
}
191192

193+
// Config defines configuration for the master
192194
type Config struct {
193195
GenericConfig *genericapiserver.Config
194196
ExtraConfig ExtraConfig
@@ -199,8 +201,8 @@ type completedConfig struct {
199201
ExtraConfig *ExtraConfig
200202
}
201203

204+
// CompletedConfig embeds a private pointer that cannot be instantiated outside of this package
202205
type CompletedConfig struct {
203-
// Embed a private pointer that cannot be instantiated outside of this package.
204206
*completedConfig
205207
}
206208

@@ -272,50 +274,50 @@ func (c *Config) createEndpointReconciler() reconcilers.EndpointReconciler {
272274
}
273275

274276
// Complete fills in any fields not set that are required to have valid data. It's mutating the receiver.
275-
func (cfg *Config) Complete() CompletedConfig {
276-
c := completedConfig{
277-
cfg.GenericConfig.Complete(cfg.ExtraConfig.VersionedInformers),
278-
&cfg.ExtraConfig,
277+
func (c *Config) Complete() CompletedConfig {
278+
cfg := completedConfig{
279+
c.GenericConfig.Complete(c.ExtraConfig.VersionedInformers),
280+
&c.ExtraConfig,
279281
}
280282

281-
serviceIPRange, apiServerServiceIP, err := ServiceIPRange(c.ExtraConfig.ServiceIPRange)
283+
serviceIPRange, apiServerServiceIP, err := ServiceIPRange(cfg.ExtraConfig.ServiceIPRange)
282284
if err != nil {
283285
klog.Fatalf("Error determining service IP ranges: %v", err)
284286
}
285-
if c.ExtraConfig.ServiceIPRange.IP == nil {
286-
c.ExtraConfig.ServiceIPRange = serviceIPRange
287+
if cfg.ExtraConfig.ServiceIPRange.IP == nil {
288+
cfg.ExtraConfig.ServiceIPRange = serviceIPRange
287289
}
288-
if c.ExtraConfig.APIServerServiceIP == nil {
289-
c.ExtraConfig.APIServerServiceIP = apiServerServiceIP
290+
if cfg.ExtraConfig.APIServerServiceIP == nil {
291+
cfg.ExtraConfig.APIServerServiceIP = apiServerServiceIP
290292
}
291293

292-
discoveryAddresses := discovery.DefaultAddresses{DefaultAddress: c.GenericConfig.ExternalAddress}
294+
discoveryAddresses := discovery.DefaultAddresses{DefaultAddress: cfg.GenericConfig.ExternalAddress}
293295
discoveryAddresses.CIDRRules = append(discoveryAddresses.CIDRRules,
294-
discovery.CIDRRule{IPRange: c.ExtraConfig.ServiceIPRange, Address: net.JoinHostPort(c.ExtraConfig.APIServerServiceIP.String(), strconv.Itoa(c.ExtraConfig.APIServerServicePort))})
295-
c.GenericConfig.DiscoveryAddresses = discoveryAddresses
296+
discovery.CIDRRule{IPRange: cfg.ExtraConfig.ServiceIPRange, Address: net.JoinHostPort(cfg.ExtraConfig.APIServerServiceIP.String(), strconv.Itoa(cfg.ExtraConfig.APIServerServicePort))})
297+
cfg.GenericConfig.DiscoveryAddresses = discoveryAddresses
296298

297-
if c.ExtraConfig.ServiceNodePortRange.Size == 0 {
299+
if cfg.ExtraConfig.ServiceNodePortRange.Size == 0 {
298300
// TODO: Currently no way to specify an empty range (do we need to allow this?)
299301
// We should probably allow this for clouds that don't require NodePort to do load-balancing (GCE)
300302
// but then that breaks the strict nestedness of ServiceType.
301303
// Review post-v1
302-
c.ExtraConfig.ServiceNodePortRange = kubeoptions.DefaultServiceNodePortRange
303-
klog.Infof("Node port range unspecified. Defaulting to %v.", c.ExtraConfig.ServiceNodePortRange)
304+
cfg.ExtraConfig.ServiceNodePortRange = kubeoptions.DefaultServiceNodePortRange
305+
klog.Infof("Node port range unspecified. Defaulting to %v.", cfg.ExtraConfig.ServiceNodePortRange)
304306
}
305307

306-
if c.ExtraConfig.EndpointReconcilerConfig.Interval == 0 {
307-
c.ExtraConfig.EndpointReconcilerConfig.Interval = DefaultEndpointReconcilerInterval
308+
if cfg.ExtraConfig.EndpointReconcilerConfig.Interval == 0 {
309+
cfg.ExtraConfig.EndpointReconcilerConfig.Interval = DefaultEndpointReconcilerInterval
308310
}
309311

310-
if c.ExtraConfig.MasterEndpointReconcileTTL == 0 {
311-
c.ExtraConfig.MasterEndpointReconcileTTL = DefaultEndpointReconcilerTTL
312+
if cfg.ExtraConfig.MasterEndpointReconcileTTL == 0 {
313+
cfg.ExtraConfig.MasterEndpointReconcileTTL = DefaultEndpointReconcilerTTL
312314
}
313315

314-
if c.ExtraConfig.EndpointReconcilerConfig.Reconciler == nil {
315-
c.ExtraConfig.EndpointReconcilerConfig.Reconciler = cfg.createEndpointReconciler()
316+
if cfg.ExtraConfig.EndpointReconcilerConfig.Reconciler == nil {
317+
cfg.ExtraConfig.EndpointReconcilerConfig.Reconciler = c.createEndpointReconciler()
316318
}
317319

318-
return CompletedConfig{&c}
320+
return CompletedConfig{&cfg}
319321
}
320322

321323
// New returns a new instance of Master from the given config.
@@ -403,6 +405,7 @@ func (c completedConfig) New(delegationTarget genericapiserver.DelegationTarget)
403405
return m, nil
404406
}
405407

408+
// InstallLegacyAPI will install the legacy APIs for the restStorageProviders if they are enabled.
406409
func (m *Master) InstallLegacyAPI(c *completedConfig, restOptionsGetter generic.RESTOptionsGetter, legacyRESTStorageProvider corerest.LegacyRESTStorageProvider) error {
407410
legacyRESTStorage, apiGroupInfo, err := legacyRESTStorageProvider.NewLegacyRESTStorage(restOptionsGetter)
408411
if err != nil {
@@ -452,7 +455,7 @@ func (m *Master) InstallAPIs(apiResourceConfigSource serverstorage.APIResourceCo
452455
}
453456
apiGroupInfo, enabled, err := restStorageBuilder.NewRESTStorage(apiResourceConfigSource, restOptionsGetter)
454457
if err != nil {
455-
return fmt.Errorf("problem initializing API group %q : %v.", groupName, err)
458+
return fmt.Errorf("problem initializing API group %q : %v", groupName, err)
456459
}
457460
if !enabled {
458461
klog.Warningf("API group %q is not enabled, skipping.", groupName)
@@ -512,6 +515,7 @@ func (n nodeAddressProvider) externalAddresses() ([]string, error) {
512515
return addrs, nil
513516
}
514517

518+
// DefaultAPIResourceConfigSource returns default configuration for an APIResource.
515519
func DefaultAPIResourceConfigSource() *serverstorage.ResourceConfig {
516520
ret := serverstorage.NewResourceConfig()
517521
// NOTE: GroupVersions listed here will be enabled by default. Don't put alpha versions in the list.

0 commit comments

Comments
 (0)