Skip to content

Commit

Permalink
compatibility fix after kubernetes dependency update
Browse files Browse the repository at this point in the history
  • Loading branch information
RainbowMango committed Dec 26, 2020
1 parent ca86517 commit c069d9f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
10 changes: 5 additions & 5 deletions pkg/cloudprovider/huaweicloud/alb.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ func (alb *ALBCloud) getSecret(namespace, secretName string) (*Secret, error) {
if ok {
kubeSecret = obj.(*v1.Secret)
} else {
secret, err := alb.kubeClient.Secrets(namespace).Get(secretName, metav1.GetOptions{})
secret, err := alb.kubeClient.Secrets(namespace).Get(context.TODO(), secretName, metav1.GetOptions{})
if err != nil {
return nil, err
}
Expand All @@ -526,7 +526,7 @@ func (alb *ALBCloud) getSecret(namespace, secretName string) (*Secret, error) {
}

func (alb *ALBCloud) getPods(name, namespace string) (*v1.PodList, error) {
service, err := alb.kubeClient.Services(namespace).Get(name, metav1.GetOptions{})
service, err := alb.kubeClient.Services(namespace).Get(context.TODO(), name, metav1.GetOptions{})
if err != nil {
return nil, err
}
Expand All @@ -539,7 +539,7 @@ func (alb *ALBCloud) getPods(name, namespace string) (*v1.PodList, error) {
set = service.Spec.Selector
labelSelector := set.AsSelector()
opts := metav1.ListOptions{LabelSelector: labelSelector.String()}
return alb.kubeClient.Pods(namespace).List(opts)
return alb.kubeClient.Pods(namespace).List(context.TODO(), opts)
}

func (alb *ALBCloud) ensureCreateLoadbalancer(albProvider *ALBClient, elbAC ElbAutoCreate, service *v1.Service) (*ALB, error) {
Expand Down Expand Up @@ -1513,7 +1513,7 @@ func (alb *ALBCloud) updateService(service *v1.Service) (*v1.Service, error) {
serviceCopy := service.DeepCopy()
for i := 0; i < MaxRetry; i++ {
toUpdate := service.DeepCopy()
toUpdate, err = alb.kubeClient.Services(toUpdate.Namespace).Update(toUpdate)
toUpdate, err = alb.kubeClient.Services(toUpdate.Namespace).Update(context.TODO(), toUpdate, metav1.UpdateOptions{})
if err == nil {
return toUpdate, nil
}
Expand All @@ -1525,7 +1525,7 @@ func (alb *ALBCloud) updateService(service *v1.Service) (*v1.Service, error) {
}

if apierrors.IsConflict(err) {
service, err = alb.kubeClient.Services(service.Namespace).Get(service.Name, metav1.GetOptions{})
service, err = alb.kubeClient.Services(service.Namespace).Get(context.TODO(), service.Name, metav1.GetOptions{})
if err != nil {
service = serviceCopy
klog.Warningf("Get service(%s/%s) error: %v", service.Namespace, service.Name, err)
Expand Down
8 changes: 4 additions & 4 deletions pkg/cloudprovider/huaweicloud/elb.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (elb *ELBCloud) getSecret(namespace, secretName string) (*Secret, error) {
if ok {
kubeSecret = obj.(*v1.Secret)
} else {
secret, err := elb.kubeClient.Secrets(namespace).Get(secretName, metav1.GetOptions{})
secret, err := elb.kubeClient.Secrets(namespace).Get(context.TODO(), secretName, metav1.GetOptions{})
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -239,7 +239,7 @@ func (elb *ELBCloud) ensureCreateListener(
}

func (elb *ELBCloud) getPods(name, namespace string) (*v1.PodList, error) {
service, err := elb.kubeClient.Services(namespace).Get(name, metav1.GetOptions{})
service, err := elb.kubeClient.Services(namespace).Get(context.TODO(), name, metav1.GetOptions{})
if err != nil {
return nil, err
}
Expand All @@ -252,7 +252,7 @@ func (elb *ELBCloud) getPods(name, namespace string) (*v1.PodList, error) {
set = service.Spec.Selector
labelSelector := set.AsSelector()
opts := metav1.ListOptions{LabelSelector: labelSelector.String()}
return elb.kubeClient.Pods(namespace).List(opts)
return elb.kubeClient.Pods(namespace).List(context.TODO(), opts)
}

// Not implemented
Expand Down Expand Up @@ -586,7 +586,7 @@ func (elb *ELBCloud) generateMembers(service *v1.Service) ([]*Member, error) {
continue
}

node, err := elb.kubeClient.Nodes().Get(item.Spec.NodeName, metav1.GetOptions{})
node, err := elb.kubeClient.Nodes().Get(context.TODO(), item.Spec.NodeName, metav1.GetOptions{})
if err != nil {
klog.Warningf("Get node(%s) error: %v", item.Spec.NodeName, err)
continue
Expand Down
12 changes: 6 additions & 6 deletions pkg/cloudprovider/huaweicloud/huaweicloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,10 +437,10 @@ func NewHWSCloud(config io.Reader) (*HWSCloud, error) {
secretInformer := cache.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
return kubeClient.Secrets(metav1.NamespaceAll).List(options)
return kubeClient.Secrets(metav1.NamespaceAll).List(context.TODO(), options)
},
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
return kubeClient.Secrets(metav1.NamespaceAll).Watch(options)
return kubeClient.Secrets(metav1.NamespaceAll).Watch(context.TODO(), options)
},
},
&v1.Secret{},
Expand Down Expand Up @@ -844,7 +844,7 @@ func updateServiceStatus(
}
}
toUpdate.Annotations[ELBMarkAnnotation] = mark
_, err := kubeClient.Services(service.Namespace).Update(toUpdate)
_, err := kubeClient.Services(service.Namespace).Update(context.TODO(), toUpdate, metav1.UpdateOptions{})
if err == nil {
return
}
Expand All @@ -858,7 +858,7 @@ func updateServiceStatus(
}

if apierrors.IsConflict(err) {
service, err = kubeClient.Services(service.Namespace).Get(service.Name, metav1.GetOptions{})
service, err = kubeClient.Services(service.Namespace).Get(context.TODO(), service.Name, metav1.GetOptions{})
if err != nil {
klog.Warningf("Get service(%s/%s) error: %v", service.Namespace, service.Name, err)
continue
Expand Down Expand Up @@ -888,7 +888,7 @@ func updateServiceMarkIfNeeded(
delete(toUpdate.Annotations, ELBMarkAnnotation)
}

_, err := kubeClient.Services(service.Namespace).Update(toUpdate)
_, err := kubeClient.Services(service.Namespace).Update(context.TODO(), toUpdate, metav1.UpdateOptions{})
if err == nil {
return
}
Expand All @@ -903,7 +903,7 @@ func updateServiceMarkIfNeeded(
}

if apierrors.IsConflict(err) {
service, err = kubeClient.Services(service.Namespace).Get(service.Name, metav1.GetOptions{})
service, err = kubeClient.Services(service.Namespace).Get(context.TODO(), service.Name, metav1.GetOptions{})
if err != nil {
klog.Warningf("Get service(%s/%s) error: %v", service.Namespace, service.Name, err)
continue
Expand Down
10 changes: 5 additions & 5 deletions pkg/cloudprovider/huaweicloud/nat.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func (nat *NATCloud) EnsureLoadBalancer(ctx context.Context, clusterName string,
}

//get service with loadbalancer type and loadbalancer ip
lbServers, err := nat.kubeClient.Services("").List(metav1.ListOptions{})
lbServers, err := nat.kubeClient.Services("").List(context.TODO(), metav1.ListOptions{})
var lbPorts []v1.ServicePort
for _, svc := range lbServers.Items {
lbType := svc.Annotations[ELBClassAnnotation]
Expand Down Expand Up @@ -362,7 +362,7 @@ func (nat *NATCloud) UpdateLoadBalancer(ctx context.Context, clusterName string,
errs = append(errs, fmt.Errorf("The port has no ipAddress binded "))
continue
}
node, err := nat.kubeClient.Nodes().Get(networkPort.FixedIps[0].IpAddress, metav1.GetOptions{})
node, err := nat.kubeClient.Nodes().Get(context.TODO(), networkPort.FixedIps[0].IpAddress, metav1.GetOptions{})
if err != nil {
klog.Errorf("Get node(%s) error: %v", networkPort.FixedIps[0].IpAddress, err)
continue
Expand Down Expand Up @@ -475,7 +475,7 @@ func (nat *NATCloud) getSecret(namespace, secretName string) (*Secret, error) {
if ok {
kubeSecret = obj.(*v1.Secret)
} else {
secret, err := nat.kubeClient.Secrets(namespace).Get(secretName, metav1.GetOptions{})
secret, err := nat.kubeClient.Secrets(namespace).Get(context.TODO(), secretName, metav1.GetOptions{})
if err != nil {
return nil, err
}
Expand All @@ -502,7 +502,7 @@ func (nat *NATCloud) getSecret(namespace, secretName string) (*Secret, error) {
}

func (nat *NATCloud) getPods(name, namespace string) (*v1.PodList, error) {
service, err := nat.kubeClient.Services(namespace).Get(name, metav1.GetOptions{})
service, err := nat.kubeClient.Services(namespace).Get(context.TODO(), name, metav1.GetOptions{})
if err != nil {
return nil, err
}
Expand All @@ -515,7 +515,7 @@ func (nat *NATCloud) getPods(name, namespace string) (*v1.PodList, error) {
set = service.Spec.Selector
labelSelector := set.AsSelector()
opts := metav1.ListOptions{LabelSelector: labelSelector.String()}
return nat.kubeClient.Pods(namespace).List(opts)
return nat.kubeClient.Pods(namespace).List(context.TODO(), opts)
}

func genDNATRuleDescription() string {
Expand Down

0 comments on commit c069d9f

Please sign in to comment.