Skip to content

Commit

Permalink
Merge pull request #729 from lubronzhan/release_1.25.3
Browse files Browse the repository at this point in the history
Release 1.25.3
  • Loading branch information
k8s-ci-robot authored May 31, 2023
2 parents 7cf45b0 + 5627737 commit 96d84d4
Show file tree
Hide file tree
Showing 12 changed files with 398 additions and 17 deletions.
Binary file added charts/vsphere-cpi-1.25.3.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.25.2
appVersion: 1.25.3
description: A Helm chart for vSphere Cloud Provider Interface Manager (CPI)
name: vsphere-cpi
version: 1.25.2
version: 1.25.3
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.25.2
VERSION=1.25.3
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 @@ -58,7 +58,7 @@ serviceAccount:
daemonset:
annotations: {}
image: gcr.io/cloud-provider-vsphere/cpi/release/manager
tag: v1.25.2
tag: v1.25.3
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.25.2
ARG VERSION=1.25.3

# This build arg controls the GOPROXY setting
ARG GOPROXY
Expand Down
2 changes: 1 addition & 1 deletion docs/book/tutorials/deploying-cpi-with-k3s.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This document is designed to show you how to integrate k3s with cloud provider v

When running with a cloud-controller-manager, it is expected to pass the node provider ID to a CCM as `<provider>://<id>`, in our case, `vsphere://1234567`. However, k3s passes it as `k3s://<hostname>`, which makes vsphere CCM not be able to find the node.

We only support `vsphere` as the provider name that is used for constructing **providerID** for both [vsphere](https://github.com/kubernetes/cloud-provider-vsphere/blob/v1.25.2/pkg/cloudprovider/vsphere/cloud.go#L51) and [vsphere-paravirtual](https://github.com/kubernetes/cloud-provider-vsphere/blob/v1.25.2/pkg/cloudprovider/vsphereparavirtual/cloud.go#L42).
We only support `vsphere` as the provider name that is used for constructing **providerID** for both [vsphere](https://github.com/kubernetes/cloud-provider-vsphere/blob/v1.25.3/pkg/cloudprovider/vsphere/cloud.go#L51) and [vsphere-paravirtual](https://github.com/kubernetes/cloud-provider-vsphere/blob/v1.25.3/pkg/cloudprovider/vsphereparavirtual/cloud.go#L42).

## How to integrate k3s with cloud provider vsphere

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.25.2
image: gcr.io/cloud-provider-vsphere/cpi/release/manager:v1.25.3
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.25.3
created: "2023-05-30T11:26:38.219849-07:00"
description: A Helm chart for vSphere Cloud Provider Interface Manager (CPI)
digest: 8b1163115a2aefdd19bf53a605f3221b7201c111054a3ccc2d95409ba11f06ba
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.25.3.tgz
version: 1.25.3
- apiVersion: v2
appVersion: 1.25.2
created: "2023-03-21T17:39:36.3208-07:00"
created: "2023-05-30T11:26:38.219062-07:00"
description: A Helm chart for vSphere Cloud Provider Interface Manager (CPI)
digest: 2bd9420c505a434f5b76ed290db828f3571c52462a91c60662dce077a586c9c3
home: https://github.com/kubernetes/cloud-provider-vsphere
Expand All @@ -22,7 +41,7 @@ entries:
version: 1.25.2
- apiVersion: v2
appVersion: 1.25.1
created: "2023-03-21T17:39:36.319884-07:00"
created: "2023-05-30T11:26:38.217544-07:00"
description: A Helm chart for vSphere Cloud Provider Interface Manager (CPI)
digest: 35106deea32e4abc4e1ca6295ee2ac82f361ea1c9af825104d8ab3260f9d4c98
home: https://github.com/kubernetes/cloud-provider-vsphere
Expand All @@ -41,7 +60,7 @@ entries:
version: 1.25.1
- apiVersion: v2
appVersion: 1.25.0
created: "2023-03-21T17:39:36.318764-07:00"
created: "2023-05-30T11:26:38.216023-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-03-21T17:39:36.317606-07:00"
created: "2023-05-30T11:26:38.214978-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-03-21T17:39:36.316081-07:00"
created: "2023-05-30T11:26:38.21344-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-03-21T17:39:36.314232-07:00"
generated: "2023-05-30T11:26:38.211242-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 96d84d4

Please sign in to comment.