From a5b121724d62235a58540ce9cb256a35a3433504 Mon Sep 17 00:00:00 2001 From: hzxuzhonghu Date: Tue, 27 Mar 2018 20:00:45 +0800 Subject: [PATCH 1/2] pv controller clean code --- .../volume/persistentvolume/pv_controller.go | 23 +++---------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/pkg/controller/volume/persistentvolume/pv_controller.go b/pkg/controller/volume/persistentvolume/pv_controller.go index c245fb15bb9..137870d2735 100644 --- a/pkg/controller/volume/persistentvolume/pv_controller.go +++ b/pkg/controller/volume/persistentvolume/pv_controller.go @@ -1045,12 +1045,7 @@ func (ctrl *PersistentVolumeController) reclaimVolume(volume *v1.PersistentVolum // doRerecycleVolumeOperationcycleVolume recycles a volume. This method is // running in standalone goroutine and already has all necessary locks. -func (ctrl *PersistentVolumeController) recycleVolumeOperation(arg interface{}) { - volume, ok := arg.(*v1.PersistentVolume) - if !ok { - glog.Errorf("Cannot convert recycleVolumeOperation argument to volume, got %#v", arg) - return - } +func (ctrl *PersistentVolumeController) recycleVolumeOperation(volume *v1.PersistentVolume) { glog.V(4).Infof("recycleVolumeOperation [%s] started", volume.Name) // This method may have been waiting for a volume lock for some time. @@ -1134,13 +1129,7 @@ func (ctrl *PersistentVolumeController) recycleVolumeOperation(arg interface{}) // deleteVolumeOperation deletes a volume. This method is running in standalone // goroutine and already has all necessary locks. -func (ctrl *PersistentVolumeController) deleteVolumeOperation(arg interface{}) error { - volume, ok := arg.(*v1.PersistentVolume) - if !ok { - glog.Errorf("Cannot convert deleteVolumeOperation argument to volume, got %#v", arg) - return nil - } - +func (ctrl *PersistentVolumeController) deleteVolumeOperation(volume *v1.PersistentVolume) error { glog.V(4).Infof("deleteVolumeOperation [%s] started", volume.Name) // This method may have been waiting for a volume lock for some time. @@ -1331,13 +1320,7 @@ func (ctrl *PersistentVolumeController) provisionClaim(claim *v1.PersistentVolum // provisionClaimOperation provisions a volume. This method is running in // standalone goroutine and already has all necessary locks. -func (ctrl *PersistentVolumeController) provisionClaimOperation(claimObj interface{}) { - claim, ok := claimObj.(*v1.PersistentVolumeClaim) - if !ok { - glog.Errorf("Cannot convert provisionClaimOperation argument to claim, got %#v", claimObj) - return - } - +func (ctrl *PersistentVolumeController) provisionClaimOperation(claim *v1.PersistentVolumeClaim) { claimClass := v1helper.GetPersistentVolumeClaimClass(claim) glog.V(4).Infof("provisionClaimOperation [%s] started, class: %q", claimToClaimKey(claim), claimClass) From ab58014cc2b412773ccf58cd70c0af25ed943536 Mon Sep 17 00:00:00 2001 From: hzxuzhonghu Date: Wed, 28 Mar 2018 09:58:51 +0800 Subject: [PATCH 2/2] LoadBalancerStatus make use of generated deep copy method --- pkg/apis/core/helper/helpers.go | 10 ---------- pkg/proxy/BUILD | 1 - pkg/proxy/service.go | 3 +-- pkg/proxy/userspace/proxier.go | 2 +- pkg/proxy/winkernel/proxier.go | 2 +- 5 files changed, 3 insertions(+), 15 deletions(-) diff --git a/pkg/apis/core/helper/helpers.go b/pkg/apis/core/helper/helpers.go index 96899f18419..8cb8595f527 100644 --- a/pkg/apis/core/helper/helpers.go +++ b/pkg/apis/core/helper/helpers.go @@ -326,16 +326,6 @@ func ingressEqual(lhs, rhs *core.LoadBalancerIngress) bool { return true } -// TODO: make method on LoadBalancerStatus? -func LoadBalancerStatusDeepCopy(lb *core.LoadBalancerStatus) *core.LoadBalancerStatus { - c := &core.LoadBalancerStatus{} - c.Ingress = make([]core.LoadBalancerIngress, len(lb.Ingress)) - for i := range lb.Ingress { - c.Ingress[i] = lb.Ingress[i] - } - return c -} - // GetAccessModesAsString returns a string representation of an array of access modes. // modes, when present, are always in the same order: RWO,ROX,RWX. func GetAccessModesAsString(modes []core.PersistentVolumeAccessMode) string { diff --git a/pkg/proxy/BUILD b/pkg/proxy/BUILD index ba71f18ca30..bb5b4b61650 100644 --- a/pkg/proxy/BUILD +++ b/pkg/proxy/BUILD @@ -18,7 +18,6 @@ go_library( deps = [ "//pkg/api/service:go_default_library", "//pkg/apis/core:go_default_library", - "//pkg/apis/core/helper:go_default_library", "//pkg/proxy/util:go_default_library", "//pkg/util/net:go_default_library", "//vendor/github.com/golang/glog:go_default_library", diff --git a/pkg/proxy/service.go b/pkg/proxy/service.go index 23911a43c5a..88e804517bb 100644 --- a/pkg/proxy/service.go +++ b/pkg/proxy/service.go @@ -30,7 +30,6 @@ import ( "k8s.io/client-go/tools/record" apiservice "k8s.io/kubernetes/pkg/api/service" api "k8s.io/kubernetes/pkg/apis/core" - "k8s.io/kubernetes/pkg/apis/core/helper" utilproxy "k8s.io/kubernetes/pkg/proxy/util" utilnet "k8s.io/kubernetes/pkg/util/net" ) @@ -91,7 +90,7 @@ func (sct *ServiceChangeTracker) newBaseServiceInfo(port *api.ServicePort, servi Protocol: port.Protocol, NodePort: int(port.NodePort), // Deep-copy in case the service instance changes - LoadBalancerStatus: *helper.LoadBalancerStatusDeepCopy(&service.Status.LoadBalancer), + LoadBalancerStatus: *service.Status.LoadBalancer.DeepCopy(), SessionAffinityType: service.Spec.SessionAffinity, StickyMaxAgeSeconds: stickyMaxAgeSeconds, OnlyNodeLocalEndpoints: onlyNodeLocalEndpoints, diff --git a/pkg/proxy/userspace/proxier.go b/pkg/proxy/userspace/proxier.go index 3fc49c06426..d1c9c5bb831 100644 --- a/pkg/proxy/userspace/proxier.go +++ b/pkg/proxy/userspace/proxier.go @@ -447,7 +447,7 @@ func (proxier *Proxier) mergeService(service *api.Service) sets.String { info.portal.port = int(servicePort.Port) info.externalIPs = service.Spec.ExternalIPs // Deep-copy in case the service instance changes - info.loadBalancerStatus = *helper.LoadBalancerStatusDeepCopy(&service.Status.LoadBalancer) + info.loadBalancerStatus = *service.Status.LoadBalancer.DeepCopy() info.nodePort = int(servicePort.NodePort) info.sessionAffinityType = service.Spec.SessionAffinity // Kube-apiserver side guarantees SessionAffinityConfig won't be nil when session affinity type is ClientIP diff --git a/pkg/proxy/winkernel/proxier.go b/pkg/proxy/winkernel/proxier.go index 595286520ce..e22295426c3 100644 --- a/pkg/proxy/winkernel/proxier.go +++ b/pkg/proxy/winkernel/proxier.go @@ -175,7 +175,7 @@ func newServiceInfo(svcPortName proxy.ServicePortName, port *api.ServicePort, se nodePort: int(port.NodePort), targetPort: port.TargetPort.IntValue(), // Deep-copy in case the service instance changes - loadBalancerStatus: *helper.LoadBalancerStatusDeepCopy(&service.Status.LoadBalancer), + loadBalancerStatus: *service.Status.LoadBalancer.DeepCopy(), sessionAffinityType: service.Spec.SessionAffinity, stickyMaxAgeSeconds: stickyMaxAgeSeconds, loadBalancerSourceRanges: make([]string, len(service.Spec.LoadBalancerSourceRanges)),