Skip to content

Commit

Permalink
Merge pull request #234 from dims/sync-with-k-k-master-jul-18
Browse files Browse the repository at this point in the history
Sync with Kubernetes master repo
  • Loading branch information
k8s-ci-robot authored Jul 20, 2018
2 parents 012086b + 0c8a774 commit 5bbf82c
Show file tree
Hide file tree
Showing 16 changed files with 820 additions and 907 deletions.
462 changes: 391 additions & 71 deletions Gopkg.lock

Large diffs are not rendered by default.

18 changes: 13 additions & 5 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ ignored = ["k8s.io/cloud-provider-openstack"]
branch = "master"
name = "github.com/golang/glog"

[[override]]
name = "k8s.io/kube-openapi"
revision = "0cf8f7e6ed1d2e3d47d02e3b6e559369af24d803"

[[override]]
name = "k8s.io/apiextensions-apiserver"
version = "kubernetes-1.11.0"

[[constraint]]
branch = "master"
name = "github.com/kubernetes-csi/drivers"
Expand Down Expand Up @@ -38,23 +46,23 @@ ignored = ["k8s.io/cloud-provider-openstack"]

[[constraint]]
name = "k8s.io/api"
version = "kubernetes-1.10.0"
version = "kubernetes-1.11.0"

[[constraint]]
name = "k8s.io/apimachinery"
version = "kubernetes-1.10.0"
version = "kubernetes-1.11.0"

[[constraint]]
name = "k8s.io/apiserver"
version = "kubernetes-1.10.0"
version = "kubernetes-1.11.0"

[[constraint]]
name = "k8s.io/client-go"
version = "kubernetes-1.10.0"
version = "kubernetes-1.11.0"

[[constraint]]
name = "k8s.io/kubernetes"
version = "1.10.0"
version = "1.11.0"

[prune]
go-tests = true
Expand Down
9 changes: 7 additions & 2 deletions cmd/openstack-cloud-controller-manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"k8s.io/kubernetes/cmd/cloud-controller-manager/app"
"k8s.io/kubernetes/cmd/cloud-controller-manager/app/options"
_ "k8s.io/kubernetes/pkg/client/metrics/prometheus" // for client metric registration
_ "k8s.io/kubernetes/pkg/features" // add the kubernetes feature gates
utilflag "k8s.io/kubernetes/pkg/util/flag"
_ "k8s.io/kubernetes/pkg/version/prometheus" // for version metric registration
"k8s.io/kubernetes/pkg/version/verflag"
Expand All @@ -53,7 +54,11 @@ func main() {
rand.Seed(time.Now().UTC().UnixNano())

goflag.CommandLine.Parse([]string{})
s := options.NewCloudControllerManagerOptions()
s, err := options.NewCloudControllerManagerOptions()
if err != nil {
glog.Fatalf("unable to initialize command options: %v", err)
}

command := &cobra.Command{
Use: "cloud-controller-manager",
Long: `The Cloud controller manager is a daemon that embeds
Expand Down Expand Up @@ -88,7 +93,7 @@ the cloud specific control loops shipped with Kubernetes.`,

glog.V(1).Infof("openstack-cloud-controller-manager version: %s", version)

s.Generic.ComponentConfig.CloudProvider = openstack.ProviderName
s.CloudProvider.Name = openstack.ProviderName
if err := command.Execute(); err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
Expand Down
6 changes: 6 additions & 0 deletions pkg/cloudprovider/providers/openstack/openstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"net"
"net/http"
"os"
"reflect"
"regexp"
"strings"
"time"
Expand Down Expand Up @@ -602,6 +603,11 @@ func (os *OpenStack) HasClusterID() bool {
func (os *OpenStack) LoadBalancer() (cloudprovider.LoadBalancer, bool) {
glog.V(4).Info("openstack.LoadBalancer() called")

if reflect.DeepEqual(os.lbOpts, LoadBalancerOpts{}) {
glog.V(4).Info("LoadBalancer section is empty/not defined in cloud-config")
return nil, false
}

network, err := os.NewNetworkV2()
if err != nil {
return nil, false
Expand Down
42 changes: 28 additions & 14 deletions pkg/cloudprovider/providers/openstack/openstack_loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,21 +489,27 @@ func (lbaas *LbaasV2) GetLoadBalancer(ctx context.Context, clusterName string, s

// The LB needs to be configured with instance addresses on the same
// subnet as the LB (aka opts.SubnetID). Currently we're just
// guessing that the node's InternalIP is the right address - and that
// should be sufficient for all "normal" cases.
// guessing that the node's InternalIP is the right address.
// In case no InternalIP can be found, ExternalIP is tried.
// If neither InternalIP nor ExternalIP can be found an error is
// returned.
func nodeAddressForLB(node *v1.Node) (string, error) {
addrs := node.Status.Addresses
if len(addrs) == 0 {
return "", ErrNoAddressFound
}

for _, addr := range addrs {
if addr.Type == v1.NodeInternalIP {
return addr.Address, nil
allowedAddrTypes := []v1.NodeAddressType{v1.NodeInternalIP, v1.NodeExternalIP}

for _, allowedAddrType := range allowedAddrTypes {
for _, addr := range addrs {
if addr.Type == allowedAddrType {
return addr.Address, nil
}
}
}

return addrs[0].Address, nil
return "", ErrNoAddressFound
}

//getStringFromServiceAnnotation searches a given v1.Service for a specific annotationKey and either returns the annotation's value or a specified defaultSetting
Expand Down Expand Up @@ -550,26 +556,34 @@ func getSubnetIDForLB(compute *gophercloud.ServiceClient, node v1.Node) (string,
}

// getNodeSecurityGroupIDForLB lists node-security-groups for specific nodes
func getNodeSecurityGroupIDForLB(compute *gophercloud.ServiceClient, nodes []*v1.Node) ([]string, error) {
nodeSecurityGroupIDs := sets.NewString()
func getNodeSecurityGroupIDForLB(compute *gophercloud.ServiceClient, network *gophercloud.ServiceClient, nodes []*v1.Node) ([]string, error) {
secGroupNames := sets.NewString()

for _, node := range nodes {
nodeName := types.NodeName(node.Name)
srv, err := getServerByName(compute, nodeName)
if err != nil {
return nodeSecurityGroupIDs.List(), err
return []string{}, err
}

// use the first node-security-groups
// case 0: node1:SG1 node2:SG1 return SG1
// case 1: node1:SG1 node2:SG2 return SG1,SG2
// case 2: node1:SG1,SG2 node2:SG3,SG4 return SG1,SG3
// case 3: node1:SG1,SG2 node2:SG2,SG3 return SG1,SG2
securityGroupName := srv.SecurityGroups[0]["name"]
nodeSecurityGroupIDs.Insert(securityGroupName.(string))
secGroupNames.Insert(srv.SecurityGroups[0]["name"].(string))
}

secGroupIDs := make([]string, secGroupNames.Len())
for i, name := range secGroupNames.List() {
secGroupID, err := groups.IDFromName(network, name)
if err != nil {
return []string{}, err
}
secGroupIDs[i] = secGroupID
}

return nodeSecurityGroupIDs.List(), nil
return secGroupIDs, nil
}

// isSecurityGroupNotFound return true while 'err' is object of gophercloud.ErrResourceNotFound
Expand Down Expand Up @@ -1021,7 +1035,7 @@ func (lbaas *LbaasV2) ensureSecurityGroup(clusterName string, apiService *v1.Ser
// find node-security-group for service
var err error
if len(lbaas.opts.NodeSecurityGroupIDs) == 0 {
lbaas.opts.NodeSecurityGroupIDs, err = getNodeSecurityGroupIDForLB(lbaas.compute, nodes)
lbaas.opts.NodeSecurityGroupIDs, err = getNodeSecurityGroupIDForLB(lbaas.compute, lbaas.network, nodes)
if err != nil {
return fmt.Errorf("failed to find node-security-group for loadbalancer service %s/%s: %v", apiService.Namespace, apiService.Name, err)
}
Expand Down Expand Up @@ -1335,7 +1349,7 @@ func (lbaas *LbaasV2) updateSecurityGroup(clusterName string, apiService *v1.Ser
originalNodeSecurityGroupIDs := lbaas.opts.NodeSecurityGroupIDs

var err error
lbaas.opts.NodeSecurityGroupIDs, err = getNodeSecurityGroupIDForLB(lbaas.compute, nodes)
lbaas.opts.NodeSecurityGroupIDs, err = getNodeSecurityGroupIDForLB(lbaas.compute, lbaas.network, nodes)
if err != nil {
return fmt.Errorf("failed to find node-security-group for loadbalancer service %s/%s: %v", apiService.Namespace, apiService.Name, err)
}
Expand Down
9 changes: 7 additions & 2 deletions pkg/cloudprovider/providers/openstack/openstack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ func TestReadConfig(t *testing.T) {
auth-url = http://auth.url
user-id = user
tenant-name = demo
region = RegionOne
[LoadBalancer]
create-monitor = yes
monitor-delay = 1m
Expand Down Expand Up @@ -136,6 +137,10 @@ func TestReadConfig(t *testing.T) {
t.Errorf("incorrect tenant name: %s", cfg.Global.TenantName)
}

if cfg.Global.Region != "RegionOne" {
t.Errorf("incorrect region: %s", cfg.Global.Region)
}

if !cfg.LoadBalancer.CreateMonitor {
t.Errorf("incorrect lb.createmonitor: %t", cfg.LoadBalancer.CreateMonitor)
}
Expand Down Expand Up @@ -615,7 +620,7 @@ func TestLoadBalancer(t *testing.T) {
t.Skip("No config found in environment")
}

versions := []string{"v2", ""}
versions := []string{"v2"}

for _, v := range versions {
t.Logf("Trying LBVersion = '%s'\n", v)
Expand Down Expand Up @@ -687,7 +692,7 @@ func TestVolumes(t *testing.T) {
tags := map[string]string{
"test": "value",
}
vol, _, _, err := os.CreateVolume("kubernetes-test-volume-"+rand.String(10), 1, "", "", &tags)
vol, _, _, _, err := os.CreateVolume("kubernetes-test-volume-"+rand.String(10), 1, "", "", &tags)
if err != nil {
t.Fatalf("Cannot create a new Cinder volume: %v", err)
}
Expand Down
13 changes: 6 additions & 7 deletions pkg/cloudprovider/providers/openstack/openstack_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@ import (
"strings"
"time"

volumeutil "k8s.io/cloud-provider-openstack/pkg/volume/util"

"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/kubernetes/pkg/cloudprovider"
kubeletapis "k8s.io/kubernetes/pkg/kubelet/apis"
k8s_volume "k8s.io/kubernetes/pkg/volume"
volumeutil "k8s.io/kubernetes/pkg/volume/util"

"github.com/gophercloud/gophercloud"
volumeexpand "github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/volumeactions"
Expand Down Expand Up @@ -451,10 +450,10 @@ func (os *OpenStack) getVolume(volumeID string) (Volume, error) {
}

// CreateVolume creates a volume of given size (in GiB)
func (os *OpenStack) CreateVolume(name string, size int, vtype, availability string, tags *map[string]string) (string, string, bool, error) {
func (os *OpenStack) CreateVolume(name string, size int, vtype, availability string, tags *map[string]string) (string, string, string, bool, error) {
volumes, err := os.volumeService("")
if err != nil {
return "", "", os.bsOpts.IgnoreVolumeAZ, fmt.Errorf("unable to initialize cinder client for region: %s, err: %v", os.region, err)
return "", "", "", os.bsOpts.IgnoreVolumeAZ, fmt.Errorf("unable to initialize cinder client for region: %s, err: %v", os.region, err)
}

opts := volumeCreateOpts{
Expand All @@ -470,11 +469,11 @@ func (os *OpenStack) CreateVolume(name string, size int, vtype, availability str
volumeID, volumeAZ, err := volumes.createVolume(opts)

if err != nil {
return "", "", os.bsOpts.IgnoreVolumeAZ, fmt.Errorf("failed to create a %d GB volume: %v", size, err)
return "", "", "", os.bsOpts.IgnoreVolumeAZ, fmt.Errorf("failed to create a %d GB volume: %v", size, err)
}

glog.Infof("Created volume %v in Availability Zone: %v Ignore volume AZ: %v", volumeID, volumeAZ, os.bsOpts.IgnoreVolumeAZ)
return volumeID, volumeAZ, os.bsOpts.IgnoreVolumeAZ, nil
glog.Infof("Created volume %v in Availability Zone: %v Region: %v Ignore volume AZ: %v", volumeID, volumeAZ, os.region, os.bsOpts.IgnoreVolumeAZ)
return volumeID, volumeAZ, os.region, os.bsOpts.IgnoreVolumeAZ, nil
}

// GetDevicePathBySerialID returns the path of an attached block storage volume, specified by its id.
Expand Down
24 changes: 10 additions & 14 deletions pkg/volume/cinder/attacher.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (plugin *cinderPlugin) NewAttacher() (volume.Attacher, error) {

func (plugin *cinderPlugin) GetDeviceMountRefs(deviceMountPath string) ([]string, error) {
mounter := plugin.host.GetMounter(plugin.GetPluginName())
return mount.GetMountRefs(mounter, deviceMountPath)
return mounter.GetMountRefs(deviceMountPath)
}

func (attacher *cinderDiskAttacher) waitOperationFinished(volumeID string) error {
Expand Down Expand Up @@ -120,13 +120,11 @@ func (attacher *cinderDiskAttacher) waitDiskAttached(instanceID, volumeID string
}

func (attacher *cinderDiskAttacher) Attach(spec *volume.Spec, nodeName types.NodeName) (string, error) {
volumeSource, _, err := getVolumeSource(spec)
volumeID, _, _, err := getVolumeInfo(spec)
if err != nil {
return "", err
}

volumeID := volumeSource.VolumeID

instanceID, err := attacher.nodeInstanceID(nodeName)
if err != nil {
return "", err
Expand Down Expand Up @@ -175,15 +173,15 @@ func (attacher *cinderDiskAttacher) VolumesAreAttached(specs []*volume.Spec, nod
volumeSpecMap := make(map[string]*volume.Spec)
volumeIDList := []string{}
for _, spec := range specs {
volumeSource, _, err := getVolumeSource(spec)
volumeID, _, _, err := getVolumeInfo(spec)
if err != nil {
glog.Errorf("Error getting volume (%q) source : %v", spec.Name(), err)
continue
}

volumeIDList = append(volumeIDList, volumeSource.VolumeID)
volumeIDList = append(volumeIDList, volumeID)
volumesAttachedCheck[spec] = true
volumeSpecMap[volumeSource.VolumeID] = spec
volumeSpecMap[volumeID] = spec
}

attachedResult, err := attacher.cinderProvider.DisksAreAttachedByName(nodeName, volumeIDList)
Expand All @@ -207,13 +205,11 @@ func (attacher *cinderDiskAttacher) VolumesAreAttached(specs []*volume.Spec, nod

func (attacher *cinderDiskAttacher) WaitForAttach(spec *volume.Spec, devicePath string, _ *v1.Pod, timeout time.Duration) (string, error) {
// NOTE: devicePath is is path as reported by Cinder, which may be incorrect and should not be used. See Issue #33128
volumeSource, _, err := getVolumeSource(spec)
volumeID, _, _, err := getVolumeInfo(spec)
if err != nil {
return "", err
}

volumeID := volumeSource.VolumeID

if devicePath == "" {
return "", fmt.Errorf("WaitForAttach failed for Cinder disk %q: devicePath is empty", volumeID)
}
Expand Down Expand Up @@ -255,12 +251,12 @@ func (attacher *cinderDiskAttacher) WaitForAttach(spec *volume.Spec, devicePath

func (attacher *cinderDiskAttacher) GetDeviceMountPath(
spec *volume.Spec) (string, error) {
volumeSource, _, err := getVolumeSource(spec)
volumeID, _, _, err := getVolumeInfo(spec)
if err != nil {
return "", err
}

return makeGlobalPDName(attacher.host, volumeSource.VolumeID), nil
return makeGlobalPDName(attacher.host, volumeID), nil
}

// FIXME: this method can be further pruned.
Expand All @@ -278,7 +274,7 @@ func (attacher *cinderDiskAttacher) MountDevice(spec *volume.Spec, devicePath st
}
}

volumeSource, readOnly, err := getVolumeSource(spec)
_, volumeFSType, readOnly, err := getVolumeInfo(spec)
if err != nil {
return err
}
Expand All @@ -290,7 +286,7 @@ func (attacher *cinderDiskAttacher) MountDevice(spec *volume.Spec, devicePath st
if notMnt {
diskMounter := volumeutil.NewSafeFormatAndMountFromHost(cinderVolumePluginName, attacher.host)
mountOptions := volumeutil.MountOptionFromSpec(spec, options...)
err = diskMounter.FormatAndMount(devicePath, deviceMountPath, volumeSource.FSType, mountOptions)
err = diskMounter.FormatAndMount(devicePath, deviceMountPath, volumeFSType, mountOptions)
if err != nil {
os.Remove(deviceMountPath)
return err
Expand Down
8 changes: 4 additions & 4 deletions pkg/volume/cinder/attacher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ func createPVSpec(name string, readOnly bool) *volume.Spec {
PersistentVolume: &v1.PersistentVolume{
Spec: v1.PersistentVolumeSpec{
PersistentVolumeSource: v1.PersistentVolumeSource{
Cinder: &v1.CinderVolumeSource{
Cinder: &v1.CinderPersistentVolumeSource{
VolumeID: name,
ReadOnly: readOnly,
},
Expand Down Expand Up @@ -610,13 +610,13 @@ func (testcase *testcase) DiskIsAttachedByName(nodeName types.NodeName, volumeID
return false, instanceID, errors.New("unexpected DiskIsAttachedByName call: wrong instanceID")
}

glog.V(4).Infof("DiskIsAttachedByName call: %s, %s, returning %v, %v", volumeID, nodeName, expected.isAttached, expected.instanceID, expected.ret)
glog.V(4).Infof("DiskIsAttachedByName call: %s, %s, returning %v, %v, %v", volumeID, nodeName, expected.isAttached, expected.instanceID, expected.ret)

return expected.isAttached, expected.instanceID, expected.ret
}

func (testcase *testcase) CreateVolume(name string, size int, vtype, availability string, tags *map[string]string) (string, string, bool, error) {
return "", "", false, errors.New("Not implemented")
func (testcase *testcase) CreateVolume(name string, size int, vtype, availability string, tags *map[string]string) (string, string, string, bool, error) {
return "", "", "", false, errors.New("Not implemented")
}

func (testcase *testcase) GetDevicePath(volumeID string) (string, error) {
Expand Down
Loading

0 comments on commit 5bbf82c

Please sign in to comment.