Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support gossip for AliCloud #6319

Merged
merged 1 commit into from
Mar 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions hack/.packages
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ k8s.io/kops/pkg/values
k8s.io/kops/protokube/cmd/protokube
k8s.io/kops/protokube/pkg/etcd
k8s.io/kops/protokube/pkg/gossip
k8s.io/kops/protokube/pkg/gossip/ali
k8s.io/kops/protokube/pkg/gossip/aws
k8s.io/kops/protokube/pkg/gossip/dns
k8s.io/kops/protokube/pkg/gossip/dns/hosts
Expand Down
15 changes: 15 additions & 0 deletions nodeup/pkg/bootstrap/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,21 @@ func (i *Installation) buildSystemdJob() *nodetasks.Service {
buffer.WriteString("\" ")
}

if os.Getenv("OSS_REGION") != "" {
buffer.WriteString("\"OSS_REGION=")
buffer.WriteString(os.Getenv("OSS_REGION"))
buffer.WriteString("\" ")
}

if os.Getenv("ALIYUN_ACCESS_KEY_ID") != "" {
buffer.WriteString("\"ALIYUN_ACCESS_KEY_ID=")
buffer.WriteString(os.Getenv("ALIYUN_ACCESS_KEY_ID"))
buffer.WriteString("\" ")
buffer.WriteString("\"ALIYUN_ACCESS_KEY_SECRET=")
buffer.WriteString(os.Getenv("ALIYUN_ACCESS_KEY_SECRET"))
buffer.WriteString("\" ")
}

if buffer.String() != "" {
manifest.Set("Service", "Environment", buffer.String())
}
Expand Down
19 changes: 19 additions & 0 deletions nodeup/pkg/model/protokube.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,25 @@ func (t *ProtokubeBuilder) ProtokubeEnvironmentVariables() string {
buffer.WriteString(" ")
}

if os.Getenv("OSS_REGION") != "" {
buffer.WriteString(" ")
buffer.WriteString("-e 'OSS_REGION=")
buffer.WriteString(os.Getenv("OSS_REGION"))
buffer.WriteString("'")
buffer.WriteString(" ")
}

if os.Getenv("ALIYUN_ACCESS_KEY_ID") != "" {
buffer.WriteString(" ")
buffer.WriteString("-e 'ALIYUN_ACCESS_KEY_ID=")
buffer.WriteString(os.Getenv("ALIYUN_ACCESS_KEY_ID"))
buffer.WriteString("'")
buffer.WriteString(" -e 'ALIYUN_ACCESS_KEY_SECRET=")
buffer.WriteString(os.Getenv("ALIYUN_ACCESS_KEY_SECRET"))
buffer.WriteString("'")
buffer.WriteString(" ")
}

t.writeProxyEnvVars(&buffer)

return buffer.String()
Expand Down
21 changes: 21 additions & 0 deletions protokube/cmd/protokube/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,21 @@ func run() error {
clusterID = osVolumes.ClusterID()
}

} else if cloud == "alicloud" {
glog.Info("Initializing AliCloud volumes")
aliVolumes, err := protokube.NewALIVolumes()
if err != nil {
glog.Errorf("Error initializing Aliyun: %q", err)
os.Exit(1)
}
volumes = aliVolumes

if clusterID == "" {
clusterID = aliVolumes.ClusterID()
}
if internalIP == nil {
internalIP = aliVolumes.InternalIP()
}
} else {
glog.Errorf("Unknown cloud %q", cloud)
os.Exit(1)
Expand Down Expand Up @@ -257,6 +272,12 @@ func run() error {
return err
}
gossipName = volumes.(*protokube.OpenstackVolumes).InstanceName()
} else if cloud == "alicloud" {
gossipSeeds, err = volumes.(*protokube.ALIVolumes).GossipSeeds()
if err != nil {
return err
}
gossipName = volumes.(*protokube.ALIVolumes).InstanceID()
} else {
glog.Fatalf("seed provider for %q not yet implemented", cloud)
}
Expand Down
13 changes: 13 additions & 0 deletions protokube/pkg/gossip/ali/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "go_default_library",
srcs = ["seeds.go"],
importpath = "k8s.io/kops/protokube/pkg/gossip/ali",
visibility = ["//visibility:public"],
deps = [
"//protokube/pkg/gossip:go_default_library",
"//vendor/github.com/denverdino/aliyungo/common:go_default_library",
"//vendor/github.com/denverdino/aliyungo/ecs:go_default_library",
],
)
79 changes: 79 additions & 0 deletions protokube/pkg/gossip/ali/seeds.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
Copyright 2018 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package ali

import (
"github.com/denverdino/aliyungo/common"
"github.com/denverdino/aliyungo/ecs"
"k8s.io/kops/protokube/pkg/gossip"
)

type SeedProvider struct {
ecs *ecs.Client
region string
tag map[string]string
}

var _ gossip.SeedProvider = &SeedProvider{}

func (p *SeedProvider) GetSeeds() ([]string, error) {
var seeds []string

// We could query at most 50 instances at a time on Aliyun ECS
maxPageSize := 50
args := &ecs.DescribeInstancesArgs{
// TODO: pending? starting?
Status: ecs.Running,
RegionId: common.Region(p.region),
Pagination: common.Pagination{
PageNumber: 1,
PageSize: maxPageSize,
},
Tag: p.tag,
}

var instances []ecs.InstanceAttributesType
for {
resp, page, err := p.ecs.DescribeInstances(args)
if err != nil {
return nil, err
}
instances = append(instances, resp...)

if page.NextPage() == nil {
break
}
args.Pagination = *(page.NextPage())
}

for _, instance := range instances {
// TODO: Multiple IP addresses?
for _, ip := range instance.VpcAttributes.PrivateIpAddress.IpAddress {
seeds = append(seeds, ip)
}
}

return seeds, nil
}

func NewSeedProvider(c *ecs.Client, region string, tag map[string]string) (*SeedProvider, error) {
return &SeedProvider{
ecs: c,
region: region,
tag: tag,
}, nil
}
6 changes: 6 additions & 0 deletions protokube/pkg/protokube/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
go_library(
name = "go_default_library",
srcs = [
"ali_volume.go",
"aws_volume.go",
"baremetal_volume.go",
"channels.go",
Expand Down Expand Up @@ -35,10 +36,12 @@ go_library(
"//pkg/resources/digitalocean:go_default_library",
"//protokube/pkg/etcd:go_default_library",
"//protokube/pkg/gossip:go_default_library",
"//protokube/pkg/gossip/ali:go_default_library",
"//protokube/pkg/gossip/aws:go_default_library",
"//protokube/pkg/gossip/dns:go_default_library",
"//protokube/pkg/gossip/gce:go_default_library",
"//protokube/pkg/gossip/openstack:go_default_library",
"//upup/pkg/fi/cloudup/aliup:go_default_library",
"//upup/pkg/fi/cloudup/awsup:go_default_library",
"//upup/pkg/fi/cloudup/gce:go_default_library",
"//upup/pkg/fi/cloudup/openstack:go_default_library",
Expand All @@ -50,6 +53,9 @@ go_library(
"//vendor/github.com/aws/aws-sdk-go/aws/request:go_default_library",
"//vendor/github.com/aws/aws-sdk-go/aws/session:go_default_library",
"//vendor/github.com/aws/aws-sdk-go/service/ec2:go_default_library",
"//vendor/github.com/denverdino/aliyungo/common:go_default_library",
"//vendor/github.com/denverdino/aliyungo/ecs:go_default_library",
"//vendor/github.com/denverdino/aliyungo/metadata:go_default_library",
"//vendor/github.com/digitalocean/godo:go_default_library",
"//vendor/github.com/golang/glog:go_default_library",
"//vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes:go_default_library",
Expand Down
Loading