Skip to content

Commit

Permalink
Merge pull request #728 from lubronzhan/release_1.26.2
Browse files Browse the repository at this point in the history
Release 1.26.2
  • Loading branch information
k8s-ci-robot authored May 31, 2023
2 parents 69dbf13 + 5e34263 commit 05d5d62
Show file tree
Hide file tree
Showing 11 changed files with 397 additions and 16 deletions.
Binary file added charts/vsphere-cpi-1.26.2.tgz
Binary file not shown.
4 changes: 2 additions & 2 deletions charts/vsphere-cpi/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
apiVersion: v2
appVersion: 1.26.1
appVersion: 1.26.2
description: A Helm chart for vSphere Cloud Provider Interface Manager (CPI)
name: vsphere-cpi
version: 1.26.1
version: 1.26.2
keywords:
- vsphere
- vmware
Expand Down
2 changes: 1 addition & 1 deletion charts/vsphere-cpi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ helm repo add vsphere-cpi https://kubernetes.github.io/cloud-provider-vsphere
helm repo update

# Package CPI Chart
VERSION=1.26.1
VERSION=1.26.2
cd charts
helm package vsphere-cpi --version $VERSION --app-version $VERSION

Expand Down
2 changes: 1 addition & 1 deletion charts/vsphere-cpi/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ serviceAccount:
daemonset:
annotations: {}
image: gcr.io/cloud-provider-vsphere/cpi/release/manager
tag: v1.26.1
tag: v1.26.2
pullPolicy: IfNotPresent
dnsPolicy: ClusterFirst
cmdline:
Expand Down
2 changes: 1 addition & 1 deletion cluster/images/controller-manager/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ ARG DISTROLESS_IMAGE=gcr.io/distroless/static-debian11@sha256:a01d47d4036cae5a67
FROM ${GOLANG_IMAGE} as builder

# This build arg is the version to embed in the CPI binary
ARG VERSION=1.26.1
ARG VERSION=1.26.2

# This build arg controls the GOPROXY setting
ARG GOPROXY
Expand Down
2 changes: 1 addition & 1 deletion docs/book/tutorials/disable-node-deletion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ spec:
priorityClassName: system-node-critical
containers:
- name: vsphere-cloud-controller-manager
image: gcr.io/cloud-provider-vsphere/cpi/release/manager:v1.26.1
image: gcr.io/cloud-provider-vsphere/cpi/release/manager:v1.26.2
args:
- --cloud-provider=vsphere
- --v=2
Expand Down
31 changes: 25 additions & 6 deletions index.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
apiVersion: v1
entries:
vsphere-cpi:
- apiVersion: v2
appVersion: 1.26.2
created: "2023-05-30T11:20:44.316207-07:00"
description: A Helm chart for vSphere Cloud Provider Interface Manager (CPI)
digest: c599a10ef8d398fb492bffe1f1159d3525db363bd24d4f2e82dd73a5f42b39ff
home: https://github.com/kubernetes/cloud-provider-vsphere
icon: https://raw.githubusercontent.com/kubernetes/cloud-provider-vsphere/master/docs/vmware_logo.png
keywords:
- vsphere
- vmware
- cloud
- provider
- cpi
name: vsphere-cpi
sources:
- https://github.com/kubernetes/cloud-provider-vsphere
urls:
- https://kubernetes.github.io/cloud-provider-vsphere/charts/vsphere-cpi-1.26.2.tgz
version: 1.26.2
- apiVersion: v2
appVersion: 1.26.1
created: "2023-04-28T14:51:00.826463-07:00"
created: "2023-05-30T11:20:44.315301-07:00"
description: A Helm chart for vSphere Cloud Provider Interface Manager (CPI)
digest: 50498be332c5119d16eee9aa6850ac36af16376448842c3d0474a1ada12dbf9e
home: https://github.com/kubernetes/cloud-provider-vsphere
Expand All @@ -22,7 +41,7 @@ entries:
version: 1.26.1
- apiVersion: v2
appVersion: 1.26.0
created: "2023-04-28T14:51:00.825587-07:00"
created: "2023-05-30T11:20:44.314472-07:00"
description: A Helm chart for vSphere Cloud Provider Interface Manager (CPI)
digest: 2ecf416700c819f408eedf9263d08dbc04cd61969576be13d8935f15605f4a69
home: https://github.com/kubernetes/cloud-provider-vsphere
Expand All @@ -41,7 +60,7 @@ entries:
version: 1.26.0
- apiVersion: v2
appVersion: 1.25.0
created: "2023-04-28T14:51:00.824498-07:00"
created: "2023-05-30T11:20:44.313625-07:00"
description: A Helm chart for vSphere Cloud Provider Interface Manager (CPI)
digest: 3d48df49fdfb8bda6b5cec1d9e9f566183a150c8c01e111eec5e22ab1f557e31
home: https://github.com/kubernetes/cloud-provider-vsphere
Expand All @@ -60,7 +79,7 @@ entries:
version: 1.25.0
- apiVersion: v2
appVersion: 1.24.2
created: "2023-04-28T14:51:00.823242-07:00"
created: "2023-05-30T11:20:44.312773-07:00"
description: A Helm chart for vSphere Cloud Provider Interface Manager (CPI)
digest: d0bfaf8a081128f9477b8d8ff00079f8506d4aa2ea899f55511d06400179b159
home: https://github.com/kubernetes/cloud-provider-vsphere
Expand All @@ -79,7 +98,7 @@ entries:
version: 1.24.2
- apiVersion: v2
appVersion: 1.24.1
created: "2023-04-28T14:51:00.822124-07:00"
created: "2023-05-30T11:20:44.311829-07:00"
description: A Helm chart for vSphere Cloud Provider Interface Manager (CPI)
digest: 6e9dec3e4c6aaeed0d7f95aa2beade986d5a0a2261509b11479ceb1a51312096
home: https://github.com/kubernetes/cloud-provider-vsphere
Expand All @@ -96,4 +115,4 @@ entries:
urls:
- https://kubernetes.github.io/cloud-provider-vsphere/charts/vsphere-cpi-1.24.1.tgz
version: 1.24.1
generated: "2023-04-28T14:51:00.820459-07:00"
generated: "2023-05-30T11:20:44.310546-07:00"
81 changes: 78 additions & 3 deletions pkg/cloudprovider/vsphere/nodemanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ package vsphere

import (
"context"
"encoding/base64"
"errors"
"fmt"
"net"
"sort"
"strings"

"gopkg.in/yaml.v2"
v1 "k8s.io/api/core/v1"
ccfg "k8s.io/cloud-provider-vsphere/pkg/cloudprovider/vsphere/config"
vcfg "k8s.io/cloud-provider-vsphere/pkg/common/config"
Expand All @@ -49,6 +52,15 @@ var (
ErrVMNotFound = errors.New("VM not found")
)

type cloudInitConfig struct {
Network struct {
Ethernets map[string]struct {
Name string `yaml:"set-name"`
Addresses []string `yaml:"addresses"`
} `yaml:"ethernets"`
} `yaml:"network"`
}

func newNodeManager(cfg *ccfg.CPIConfig, cm *cm.ConnectionManager) *NodeManager {
return &NodeManager{
nodeNameMap: make(map[string]*NodeInfo),
Expand Down Expand Up @@ -191,7 +203,7 @@ func (nm *NodeManager) DiscoverNode(nodeID string, searchBy cm.FindVM) error {
}

var oVM mo.VirtualMachine
err = vmDI.VM.Properties(ctx, vmDI.VM.Reference(), []string{"guest", "summary"}, &oVM)
err = vmDI.VM.Properties(ctx, vmDI.VM.Reference(), []string{"guest", "summary", "config"}, &oVM)
if err != nil {
klog.Errorf("Error collecting properties for vm=%+v in vc=%s and datacenter=%s: %v",
vmDI.VM, vmDI.VcServer, vmDI.DataCenter.Name(), err)
Expand Down Expand Up @@ -291,10 +303,17 @@ func (nm *NodeManager) DiscoverNode(nodeID string, searchBy cm.FindVM) error {
return fmt.Errorf("unable to find suitable IP address for node after filtering out localhost IPs")
}

sortedNonLocalhostIPs, err := sortStaticallyConfiguredAddressesFirst(oVM.Config.ExtraConfig, nonLocalhostIPs)
if err != nil {
klog.Errorf("Error sorting statically configured addresses for vm=%+v in vc=%s and datacenter=%s: %v",
vmDI.VM, vmDI.VcServer, vmDI.DataCenter.Name(), err)
return err
}

for _, ipFamily := range ipFamilies {
klog.V(6).Infof("ipFamily: %q nonLocalhostIPs: %q", ipFamily, nonLocalhostIPs)
klog.V(6).Infof("ipFamily: %q nonLocalhostIPs: %q", ipFamily, sortedNonLocalhostIPs)
discoveredInternal, discoveredExternal := discoverIPs(
nonLocalhostIPs,
sortedNonLocalhostIPs,
ipFamily,
internalNetworkSubnets,
externalNetworkSubnets,
Expand Down Expand Up @@ -652,3 +671,59 @@ func (nm *NodeManager) getNodeNameByUUID(UUID string) string {
}
return ""
}

func guestInfoMetadata(extraConfig []types.BaseOptionValue) (string, string) {
var guestInfo, encoding string
for _, option := range extraConfig {
value := option.GetOptionValue()
switch value.Key {
case "guestinfo.metadata":
guestInfo, _ = value.Value.(string)
case "guestinfo.metadata.encoding":
encoding, _ = value.Value.(string)
}
}
return guestInfo, encoding
}

// sortStaticallyConfiguredAddressesFirst prefers addresses that are from the
// guestInfo but only if they are on a NIC already. It preserves the order in which
// the addresses appear in the guestInfo. For addresses not found in the guestInfo,
// it preserves the order in which they appear in nonlocalhostIPs.
func sortStaticallyConfiguredAddressesFirst(extraConfig []types.BaseOptionValue, nonLocalhostIPs []*ipAddrNetworkName) ([]*ipAddrNetworkName, error) {
guestInfo, encoding := guestInfoMetadata(extraConfig)

if guestInfo != "" && encoding == "base64" {
value, err := base64.StdEncoding.DecodeString(guestInfo)
if err != nil {
return nil, err
}

guestInfo := &cloudInitConfig{}
err = yaml.Unmarshal(value, guestInfo)
if err != nil {
return nil, err
}

// Map of guestInfo IP -> index that describes the order they appear in the guestInfo
guestInfoAddresses := make(map[string]int)
for _, eth := range guestInfo.Network.Ethernets {
for _, address := range eth.Addresses {
ip := net.ParseIP(strings.Split(address, "/")[0])
guestInfoAddresses[ip.String()] = len(guestInfoAddresses)
}
}

// Sort nonlocalhostIPs by the following comparator for two IP addresses: a and b
// if a is statically configured, but b is not then a should be prioritized before b
// if b is statically configured, but a is not then a should not be prioritized before b
// if a and b are both statically configured, then use the index from the guest info
sort.SliceStable(nonLocalhostIPs, func(i, j int) bool {
aIndex, aFound := guestInfoAddresses[nonLocalhostIPs[i].ipAddr]
bIndex, bFound := guestInfoAddresses[nonLocalhostIPs[j].ipAddr]

return aFound && !bFound || aFound && bFound && aIndex < bIndex
})
}
return nonLocalhostIPs, nil
}
Loading

0 comments on commit 05d5d62

Please sign in to comment.