mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 19:31:44 +00:00
Fixes golint errors in pkg/controller
This commit is contained in:
parent
820b67e41f
commit
056f871bed
@ -44,13 +44,16 @@ type ReplicationManager struct {
|
|||||||
syncHandler func(controllerSpec api.ReplicationController) error
|
syncHandler func(controllerSpec api.ReplicationController) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// An interface that knows how to add or delete pods
|
// PodControlInterface is an interface that knows how to add or delete pods
|
||||||
// created as an interface to allow testing.
|
// created as an interface to allow testing.
|
||||||
type PodControlInterface interface {
|
type PodControlInterface interface {
|
||||||
|
// createReplica creates new replicated pods according to the spec.
|
||||||
createReplica(controllerSpec api.ReplicationController)
|
createReplica(controllerSpec api.ReplicationController)
|
||||||
|
// deletePod deletes the pod identified by podID.
|
||||||
deletePod(podID string) error
|
deletePod(podID string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RealPodControl is the default implementation of PodControllerInterface.
|
||||||
type RealPodControl struct {
|
type RealPodControl struct {
|
||||||
kubeClient client.ClientInterface
|
kubeClient client.ClientInterface
|
||||||
}
|
}
|
||||||
@ -77,6 +80,7 @@ func (r RealPodControl) deletePod(podID string) error {
|
|||||||
return r.kubeClient.DeletePod(podID)
|
return r.kubeClient.DeletePod(podID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MakeReplicationManager craetes a new ReplicationManager.
|
||||||
func MakeReplicationManager(etcdClient tools.EtcdClient, kubeClient client.ClientInterface) *ReplicationManager {
|
func MakeReplicationManager(etcdClient tools.EtcdClient, kubeClient client.ClientInterface) *ReplicationManager {
|
||||||
rm := &ReplicationManager{
|
rm := &ReplicationManager{
|
||||||
kubeClient: kubeClient,
|
kubeClient: kubeClient,
|
||||||
@ -91,7 +95,7 @@ func MakeReplicationManager(etcdClient tools.EtcdClient, kubeClient client.Clien
|
|||||||
return rm
|
return rm
|
||||||
}
|
}
|
||||||
|
|
||||||
// Begin watching and syncing.
|
// Run begins watching and syncing.
|
||||||
func (rm *ReplicationManager) Run(period time.Duration) {
|
func (rm *ReplicationManager) Run(period time.Duration) {
|
||||||
rm.syncTime = time.Tick(period)
|
rm.syncTime = time.Tick(period)
|
||||||
go util.Forever(func() { rm.watchControllers() }, period)
|
go util.Forever(func() { rm.watchControllers() }, period)
|
||||||
@ -145,9 +149,8 @@ func (rm *ReplicationManager) handleWatchResponse(response *etcd.Response) (*api
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &controllerSpec, nil
|
return &controllerSpec, nil
|
||||||
} else {
|
|
||||||
return nil, fmt.Errorf("response node is null %#v", response)
|
|
||||||
}
|
}
|
||||||
|
return nil, fmt.Errorf("response node is null %#v", response)
|
||||||
} else if response.Action == "delete" {
|
} else if response.Action == "delete" {
|
||||||
// Ensure that the final state of a replication controller is applied before it is deleted.
|
// Ensure that the final state of a replication controller is applied before it is deleted.
|
||||||
// Otherwise, a replication controller could be modified and then deleted (for example, from 3 to 0
|
// Otherwise, a replication controller could be modified and then deleted (for example, from 3 to 0
|
||||||
@ -158,9 +161,8 @@ func (rm *ReplicationManager) handleWatchResponse(response *etcd.Response) (*api
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &controllerSpec, nil
|
return &controllerSpec, nil
|
||||||
} else {
|
|
||||||
return nil, fmt.Errorf("previous node is null %#v", response)
|
|
||||||
}
|
}
|
||||||
|
return nil, fmt.Errorf("previous node is null %#v", response)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
@ -41,7 +41,7 @@ func expectNoError(t *testing.T, err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeUrl(suffix string) string {
|
func makeURL(suffix string) string {
|
||||||
return apiPath + suffix
|
return apiPath + suffix
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,7 +205,7 @@ func TestCreateReplica(t *testing.T) {
|
|||||||
// DesiredState: controllerSpec.DesiredState.PodTemplate.DesiredState,
|
// DesiredState: controllerSpec.DesiredState.PodTemplate.DesiredState,
|
||||||
//}
|
//}
|
||||||
// TODO: fix this so that it validates the body.
|
// TODO: fix this so that it validates the body.
|
||||||
fakeHandler.ValidateRequest(t, makeUrl("/pods"), "POST", nil)
|
fakeHandler.ValidateRequest(t, makeURL("/pods"), "POST", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHandleWatchResponseNotSet(t *testing.T) {
|
func TestHandleWatchResponseNotSet(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user