mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 19:31:44 +00:00
fix golint errors for pkg/master, together with cheftako
This commit is contained in:
parent
5fbda60c14
commit
ed8767cded
@ -137,7 +137,6 @@ pkg/kubelet/status/testing
|
|||||||
pkg/kubelet/sysctl
|
pkg/kubelet/sysctl
|
||||||
pkg/kubelet/types
|
pkg/kubelet/types
|
||||||
pkg/kubemark
|
pkg/kubemark
|
||||||
pkg/master
|
|
||||||
pkg/master/controller/crdregistration
|
pkg/master/controller/crdregistration
|
||||||
pkg/master/tunneler
|
pkg/master/tunneler
|
||||||
pkg/proxy/apis/config
|
pkg/proxy/apis/config
|
||||||
|
@ -31,6 +31,7 @@ import (
|
|||||||
corev1client "k8s.io/client-go/kubernetes/typed/core/v1"
|
corev1client "k8s.io/client-go/kubernetes/typed/core/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ClientCARegistrationHook defines CA registration hook request structure
|
||||||
type ClientCARegistrationHook struct {
|
type ClientCARegistrationHook struct {
|
||||||
ClientCA []byte
|
ClientCA []byte
|
||||||
|
|
||||||
@ -41,6 +42,7 @@ type ClientCARegistrationHook struct {
|
|||||||
RequestHeaderAllowedNames []string
|
RequestHeaderAllowedNames []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PostStartHook initializes client CA configmap for the API server
|
||||||
func (h ClientCARegistrationHook) PostStartHook(hookContext genericapiserver.PostStartHookContext) error {
|
func (h ClientCARegistrationHook) PostStartHook(hookContext genericapiserver.PostStartHookContext) error {
|
||||||
// initializing CAs is important so that aggregated API servers can come up with "normal" config.
|
// initializing CAs is important so that aggregated API servers can come up with "normal" config.
|
||||||
// We've seen lagging etcd before, so we want to retry this a few times before we decide to crashloop
|
// We've seen lagging etcd before, so we want to retry this a few times before we decide to crashloop
|
||||||
|
@ -131,11 +131,13 @@ func (c *completedConfig) NewBootstrapController(legacyRESTStorage corerest.Lega
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PostStartHook initiates the core controller loops that must exist for bootstrapping.
|
||||||
func (c *Controller) PostStartHook(hookContext genericapiserver.PostStartHookContext) error {
|
func (c *Controller) PostStartHook(hookContext genericapiserver.PostStartHookContext) error {
|
||||||
c.Start()
|
c.Start()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PreShutdownHook triggers the actions needed to shut down the API Server cleanly.
|
||||||
func (c *Controller) PreShutdownHook() error {
|
func (c *Controller) PreShutdownHook() error {
|
||||||
c.Stop()
|
c.Stop()
|
||||||
return nil
|
return nil
|
||||||
@ -171,6 +173,7 @@ func (c *Controller) Start() {
|
|||||||
c.runner.Start()
|
c.runner.Start()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Stop cleans up this API Servers endpoint reconciliation leases so another master can take over more quickly.
|
||||||
func (c *Controller) Stop() {
|
func (c *Controller) Stop() {
|
||||||
if c.runner != nil {
|
if c.runner != nil {
|
||||||
c.runner.Stop()
|
c.runner.Stop()
|
||||||
@ -279,7 +282,7 @@ func createEndpointPortSpec(endpointPort int, endpointPortName string, extraEndp
|
|||||||
return endpointPorts
|
return endpointPorts
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateMasterServiceIfNeeded will create the specified service if it
|
// CreateOrUpdateMasterServiceIfNeeded will create the specified service if it
|
||||||
// doesn't already exist.
|
// doesn't already exist.
|
||||||
func (c *Controller) CreateOrUpdateMasterServiceIfNeeded(serviceName string, serviceIP net.IP, servicePorts []corev1.ServicePort, serviceType corev1.ServiceType, reconcile bool) error {
|
func (c *Controller) CreateOrUpdateMasterServiceIfNeeded(serviceName string, serviceIP net.IP, servicePorts []corev1.ServicePort, serviceType corev1.ServiceType, reconcile bool) error {
|
||||||
if s, err := c.ServiceClient.Services(metav1.NamespaceDefault).Get(serviceName, metav1.GetOptions{}); err == nil {
|
if s, err := c.ServiceClient.Services(metav1.NamespaceDefault).Get(serviceName, metav1.GetOptions{}); err == nil {
|
||||||
|
@ -34,7 +34,7 @@ func TestReconcileEndpoints(t *testing.T) {
|
|||||||
om := func(name string) metav1.ObjectMeta {
|
om := func(name string) metav1.ObjectMeta {
|
||||||
return metav1.ObjectMeta{Namespace: ns, Name: name}
|
return metav1.ObjectMeta{Namespace: ns, Name: name}
|
||||||
}
|
}
|
||||||
reconcile_tests := []struct {
|
reconcileTests := []struct {
|
||||||
testName string
|
testName string
|
||||||
serviceName string
|
serviceName string
|
||||||
ip string
|
ip string
|
||||||
@ -387,7 +387,7 @@ func TestReconcileEndpoints(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, test := range reconcile_tests {
|
for _, test := range reconcileTests {
|
||||||
fakeClient := fake.NewSimpleClientset()
|
fakeClient := fake.NewSimpleClientset()
|
||||||
if test.endpoints != nil {
|
if test.endpoints != nil {
|
||||||
fakeClient = fake.NewSimpleClientset(test.endpoints)
|
fakeClient = fake.NewSimpleClientset(test.endpoints)
|
||||||
@ -437,7 +437,7 @@ func TestReconcileEndpoints(t *testing.T) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
non_reconcile_tests := []struct {
|
nonReconcileTests := []struct {
|
||||||
testName string
|
testName string
|
||||||
serviceName string
|
serviceName string
|
||||||
ip string
|
ip string
|
||||||
@ -506,7 +506,7 @@ func TestReconcileEndpoints(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, test := range non_reconcile_tests {
|
for _, test := range nonReconcileTests {
|
||||||
fakeClient := fake.NewSimpleClientset()
|
fakeClient := fake.NewSimpleClientset()
|
||||||
if test.endpoints != nil {
|
if test.endpoints != nil {
|
||||||
fakeClient = fake.NewSimpleClientset(test.endpoints)
|
fakeClient = fake.NewSimpleClientset(test.endpoints)
|
||||||
@ -564,7 +564,7 @@ func TestCreateOrUpdateMasterService(t *testing.T) {
|
|||||||
return metav1.ObjectMeta{Namespace: ns, Name: name}
|
return metav1.ObjectMeta{Namespace: ns, Name: name}
|
||||||
}
|
}
|
||||||
|
|
||||||
create_tests := []struct {
|
createTests := []struct {
|
||||||
testName string
|
testName string
|
||||||
serviceName string
|
serviceName string
|
||||||
servicePorts []corev1.ServicePort
|
servicePorts []corev1.ServicePort
|
||||||
@ -592,7 +592,7 @@ func TestCreateOrUpdateMasterService(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, test := range create_tests {
|
for _, test := range createTests {
|
||||||
master := Controller{}
|
master := Controller{}
|
||||||
fakeClient := fake.NewSimpleClientset()
|
fakeClient := fake.NewSimpleClientset()
|
||||||
master.ServiceClient = fakeClient.CoreV1()
|
master.ServiceClient = fakeClient.CoreV1()
|
||||||
@ -618,7 +618,7 @@ func TestCreateOrUpdateMasterService(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
reconcile_tests := []struct {
|
reconcileTests := []struct {
|
||||||
testName string
|
testName string
|
||||||
serviceName string
|
serviceName string
|
||||||
servicePorts []corev1.ServicePort
|
servicePorts []corev1.ServicePort
|
||||||
@ -874,7 +874,7 @@ func TestCreateOrUpdateMasterService(t *testing.T) {
|
|||||||
expectUpdate: nil,
|
expectUpdate: nil,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, test := range reconcile_tests {
|
for _, test := range reconcileTests {
|
||||||
master := Controller{}
|
master := Controller{}
|
||||||
fakeClient := fake.NewSimpleClientset(test.service)
|
fakeClient := fake.NewSimpleClientset(test.service)
|
||||||
master.ServiceClient = fakeClient.CoreV1()
|
master.ServiceClient = fakeClient.CoreV1()
|
||||||
@ -903,7 +903,7 @@ func TestCreateOrUpdateMasterService(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
non_reconcile_tests := []struct {
|
nonReconcileTests := []struct {
|
||||||
testName string
|
testName string
|
||||||
serviceName string
|
serviceName string
|
||||||
servicePorts []corev1.ServicePort
|
servicePorts []corev1.ServicePort
|
||||||
@ -933,7 +933,7 @@ func TestCreateOrUpdateMasterService(t *testing.T) {
|
|||||||
expectUpdate: nil,
|
expectUpdate: nil,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, test := range non_reconcile_tests {
|
for _, test := range nonReconcileTests {
|
||||||
master := Controller{}
|
master := Controller{}
|
||||||
fakeClient := fake.NewSimpleClientset(test.service)
|
fakeClient := fake.NewSimpleClientset(test.service)
|
||||||
master.ServiceClient = fakeClient.CoreV1()
|
master.ServiceClient = fakeClient.CoreV1()
|
||||||
|
@ -16,8 +16,8 @@ limitations under the License.
|
|||||||
|
|
||||||
package master
|
package master
|
||||||
|
|
||||||
// These imports are the API groups the API server will support.
|
|
||||||
import (
|
import (
|
||||||
|
// These imports are the API groups the API server will support.
|
||||||
_ "k8s.io/kubernetes/pkg/apis/admission/install"
|
_ "k8s.io/kubernetes/pkg/apis/admission/install"
|
||||||
_ "k8s.io/kubernetes/pkg/apis/admissionregistration/install"
|
_ "k8s.io/kubernetes/pkg/apis/admissionregistration/install"
|
||||||
_ "k8s.io/kubernetes/pkg/apis/apps/install"
|
_ "k8s.io/kubernetes/pkg/apis/apps/install"
|
||||||
|
@ -118,6 +118,7 @@ const (
|
|||||||
DefaultEndpointReconcilerTTL = 15 * time.Second
|
DefaultEndpointReconcilerTTL = 15 * time.Second
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ExtraConfig defines extra configuration for the master
|
||||||
type ExtraConfig struct {
|
type ExtraConfig struct {
|
||||||
ClientCARegistrationHook ClientCARegistrationHook
|
ClientCARegistrationHook ClientCARegistrationHook
|
||||||
|
|
||||||
@ -189,6 +190,7 @@ type ExtraConfig struct {
|
|||||||
VersionedInformers informers.SharedInformerFactory
|
VersionedInformers informers.SharedInformerFactory
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Config defines configuration for the master
|
||||||
type Config struct {
|
type Config struct {
|
||||||
GenericConfig *genericapiserver.Config
|
GenericConfig *genericapiserver.Config
|
||||||
ExtraConfig ExtraConfig
|
ExtraConfig ExtraConfig
|
||||||
@ -199,8 +201,8 @@ type completedConfig struct {
|
|||||||
ExtraConfig *ExtraConfig
|
ExtraConfig *ExtraConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CompletedConfig embeds a private pointer that cannot be instantiated outside of this package
|
||||||
type CompletedConfig struct {
|
type CompletedConfig struct {
|
||||||
// Embed a private pointer that cannot be instantiated outside of this package.
|
|
||||||
*completedConfig
|
*completedConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -272,50 +274,50 @@ func (c *Config) createEndpointReconciler() reconcilers.EndpointReconciler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Complete fills in any fields not set that are required to have valid data. It's mutating the receiver.
|
// Complete fills in any fields not set that are required to have valid data. It's mutating the receiver.
|
||||||
func (cfg *Config) Complete() CompletedConfig {
|
func (c *Config) Complete() CompletedConfig {
|
||||||
c := completedConfig{
|
cfg := completedConfig{
|
||||||
cfg.GenericConfig.Complete(cfg.ExtraConfig.VersionedInformers),
|
c.GenericConfig.Complete(c.ExtraConfig.VersionedInformers),
|
||||||
&cfg.ExtraConfig,
|
&c.ExtraConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
serviceIPRange, apiServerServiceIP, err := ServiceIPRange(c.ExtraConfig.ServiceIPRange)
|
serviceIPRange, apiServerServiceIP, err := ServiceIPRange(cfg.ExtraConfig.ServiceIPRange)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Fatalf("Error determining service IP ranges: %v", err)
|
klog.Fatalf("Error determining service IP ranges: %v", err)
|
||||||
}
|
}
|
||||||
if c.ExtraConfig.ServiceIPRange.IP == nil {
|
if cfg.ExtraConfig.ServiceIPRange.IP == nil {
|
||||||
c.ExtraConfig.ServiceIPRange = serviceIPRange
|
cfg.ExtraConfig.ServiceIPRange = serviceIPRange
|
||||||
}
|
}
|
||||||
if c.ExtraConfig.APIServerServiceIP == nil {
|
if cfg.ExtraConfig.APIServerServiceIP == nil {
|
||||||
c.ExtraConfig.APIServerServiceIP = apiServerServiceIP
|
cfg.ExtraConfig.APIServerServiceIP = apiServerServiceIP
|
||||||
}
|
}
|
||||||
|
|
||||||
discoveryAddresses := discovery.DefaultAddresses{DefaultAddress: c.GenericConfig.ExternalAddress}
|
discoveryAddresses := discovery.DefaultAddresses{DefaultAddress: cfg.GenericConfig.ExternalAddress}
|
||||||
discoveryAddresses.CIDRRules = append(discoveryAddresses.CIDRRules,
|
discoveryAddresses.CIDRRules = append(discoveryAddresses.CIDRRules,
|
||||||
discovery.CIDRRule{IPRange: c.ExtraConfig.ServiceIPRange, Address: net.JoinHostPort(c.ExtraConfig.APIServerServiceIP.String(), strconv.Itoa(c.ExtraConfig.APIServerServicePort))})
|
discovery.CIDRRule{IPRange: cfg.ExtraConfig.ServiceIPRange, Address: net.JoinHostPort(cfg.ExtraConfig.APIServerServiceIP.String(), strconv.Itoa(cfg.ExtraConfig.APIServerServicePort))})
|
||||||
c.GenericConfig.DiscoveryAddresses = discoveryAddresses
|
cfg.GenericConfig.DiscoveryAddresses = discoveryAddresses
|
||||||
|
|
||||||
if c.ExtraConfig.ServiceNodePortRange.Size == 0 {
|
if cfg.ExtraConfig.ServiceNodePortRange.Size == 0 {
|
||||||
// TODO: Currently no way to specify an empty range (do we need to allow this?)
|
// TODO: Currently no way to specify an empty range (do we need to allow this?)
|
||||||
// We should probably allow this for clouds that don't require NodePort to do load-balancing (GCE)
|
// We should probably allow this for clouds that don't require NodePort to do load-balancing (GCE)
|
||||||
// but then that breaks the strict nestedness of ServiceType.
|
// but then that breaks the strict nestedness of ServiceType.
|
||||||
// Review post-v1
|
// Review post-v1
|
||||||
c.ExtraConfig.ServiceNodePortRange = kubeoptions.DefaultServiceNodePortRange
|
cfg.ExtraConfig.ServiceNodePortRange = kubeoptions.DefaultServiceNodePortRange
|
||||||
klog.Infof("Node port range unspecified. Defaulting to %v.", c.ExtraConfig.ServiceNodePortRange)
|
klog.Infof("Node port range unspecified. Defaulting to %v.", cfg.ExtraConfig.ServiceNodePortRange)
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.ExtraConfig.EndpointReconcilerConfig.Interval == 0 {
|
if cfg.ExtraConfig.EndpointReconcilerConfig.Interval == 0 {
|
||||||
c.ExtraConfig.EndpointReconcilerConfig.Interval = DefaultEndpointReconcilerInterval
|
cfg.ExtraConfig.EndpointReconcilerConfig.Interval = DefaultEndpointReconcilerInterval
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.ExtraConfig.MasterEndpointReconcileTTL == 0 {
|
if cfg.ExtraConfig.MasterEndpointReconcileTTL == 0 {
|
||||||
c.ExtraConfig.MasterEndpointReconcileTTL = DefaultEndpointReconcilerTTL
|
cfg.ExtraConfig.MasterEndpointReconcileTTL = DefaultEndpointReconcilerTTL
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.ExtraConfig.EndpointReconcilerConfig.Reconciler == nil {
|
if cfg.ExtraConfig.EndpointReconcilerConfig.Reconciler == nil {
|
||||||
c.ExtraConfig.EndpointReconcilerConfig.Reconciler = cfg.createEndpointReconciler()
|
cfg.ExtraConfig.EndpointReconcilerConfig.Reconciler = c.createEndpointReconciler()
|
||||||
}
|
}
|
||||||
|
|
||||||
return CompletedConfig{&c}
|
return CompletedConfig{&cfg}
|
||||||
}
|
}
|
||||||
|
|
||||||
// New returns a new instance of Master from the given config.
|
// New returns a new instance of Master from the given config.
|
||||||
@ -403,6 +405,7 @@ func (c completedConfig) New(delegationTarget genericapiserver.DelegationTarget)
|
|||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InstallLegacyAPI will install the legacy APIs for the restStorageProviders if they are enabled.
|
||||||
func (m *Master) InstallLegacyAPI(c *completedConfig, restOptionsGetter generic.RESTOptionsGetter, legacyRESTStorageProvider corerest.LegacyRESTStorageProvider) error {
|
func (m *Master) InstallLegacyAPI(c *completedConfig, restOptionsGetter generic.RESTOptionsGetter, legacyRESTStorageProvider corerest.LegacyRESTStorageProvider) error {
|
||||||
legacyRESTStorage, apiGroupInfo, err := legacyRESTStorageProvider.NewLegacyRESTStorage(restOptionsGetter)
|
legacyRESTStorage, apiGroupInfo, err := legacyRESTStorageProvider.NewLegacyRESTStorage(restOptionsGetter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -452,7 +455,7 @@ func (m *Master) InstallAPIs(apiResourceConfigSource serverstorage.APIResourceCo
|
|||||||
}
|
}
|
||||||
apiGroupInfo, enabled, err := restStorageBuilder.NewRESTStorage(apiResourceConfigSource, restOptionsGetter)
|
apiGroupInfo, enabled, err := restStorageBuilder.NewRESTStorage(apiResourceConfigSource, restOptionsGetter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("problem initializing API group %q : %v.", groupName, err)
|
return fmt.Errorf("problem initializing API group %q : %v", groupName, err)
|
||||||
}
|
}
|
||||||
if !enabled {
|
if !enabled {
|
||||||
klog.Warningf("API group %q is not enabled, skipping.", groupName)
|
klog.Warningf("API group %q is not enabled, skipping.", groupName)
|
||||||
@ -512,6 +515,7 @@ func (n nodeAddressProvider) externalAddresses() ([]string, error) {
|
|||||||
return addrs, nil
|
return addrs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DefaultAPIResourceConfigSource returns default configuration for an APIResource.
|
||||||
func DefaultAPIResourceConfigSource() *serverstorage.ResourceConfig {
|
func DefaultAPIResourceConfigSource() *serverstorage.ResourceConfig {
|
||||||
ret := serverstorage.NewResourceConfig()
|
ret := serverstorage.NewResourceConfig()
|
||||||
// NOTE: GroupVersions listed here will be enabled by default. Don't put alpha versions in the list.
|
// NOTE: GroupVersions listed here will be enabled by default. Don't put alpha versions in the list.
|
||||||
|
Loading…
Reference in New Issue
Block a user