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

✨ get userid automatically #56

Merged
merged 2 commits into from
May 13, 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
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
# Changelog
## [ 1.3.4 ] - 2019-05-13
### Added
- get userid automatically [@magicsong](https://github.com/yunify/qingcloud-cloud-controller-manager/pull/55)

### Changed
- simplify `Makefile`

## [ 1.3.3 ] - 2019-05-04
### Added
- support UDP [@magicsong](https://github.com/yunify/qingcloud-cloud-controller-manager/pull/53)
- support UDP [@magicsong](https://github.com/yunify/qingcloud-cloud-controller-manager/pull/54)
### Fixed
- fixed that `https` port becomes `http` in qingcloud console [@magicsong](https://github.com/yunify/qingcloud-cloud-controller-manager/pull/53)
- fixed that `https` port becomes `http` in qingcloud console [@magicsong](https://github.com/yunify/qingcloud-cloud-controller-manager/pull/54)
- fixed securityGroup is not deleted in cloud

## [ 1.3.2 ] - 2019-05-06
Expand Down
35 changes: 4 additions & 31 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Vars describing project
NAME= qingcloud-cloud-controller-manager
GIT_REPOSITORY= github.com/yunify/qingcloud-cloud-controller-manager
IMG?= kubespheredev/cloud-controller-manager:v1.3.3
IMG?= kubespheredev/cloud-controller-manager:v1.3.4

# Generate vars to be included from external script
# Allows using bash to generate complex vars, such as project versions
Expand Down Expand Up @@ -35,25 +35,6 @@ BUILD_DATE ?= $(shell date -u +%Y%m%d.%H%M%S)
GIT_SHA1 ?= unknown_sha1

IMAGE_LABLE ?= $(BUILD_LABEL)
# Vars for export ; generate list of ENV vars based on matching export prefix
# Use strip to get rid of excessive spaces due to the foreach / filter / if logic
EXPORT_VAR_PREFIX = EXPORT_VAR_
EXPORT_VARS = $(strip $(foreach v,$(filter $(EXPORT_VAR_PREFIX)%,$(.VARIABLES)),$(if $(filter environment%,$(origin $(v))),$(v))))

# Vars for go phase
# All vars which being with prefix will be included in ldflags
# Defaulting to full static build
GO_VARIABLE_PREFIX = GO_VAR_
GO_VAR_BUILD_LABEL := $(BUILD_LABEL)
GO_VAR_VERSION := $(VERSION)
GO_VAR_GIT_SHA1 := $(GIT_SHA1)
GO_VAR_BUILD_LABEL := $(BUILD_LABEL)
GO_LDFLAGS = $(foreach v,$(filter $(GO_VARIABLE_PREFIX)%, $(.VARIABLES)),-X github.com/yunify/qingcloud-cloud-controller-manager/qingcloud.$(patsubst $(GO_VARIABLE_PREFIX)%,%,$(v))=$(value $(value v)))
GO_BUILD_FLAGS = -a -tags netgo -installsuffix nocgo -ldflags "$(GO_LDFLAGS)"

#src
qingcloud-cloud-controller-manager_pkg = $(subst $(GIT_REPOSITORY)/,,$(shell go list -f '{{ join .Deps "\n" }}' $(GIT_REPOSITORY) | grep "^$(GIT_REPOSITORY)" |grep -v "^$(GIT_REPOSITORY)/vendor/" ))
qingcloud-cloud-controller-manager_pkg += .

# default just build binary
default : go-build
Expand All @@ -65,21 +46,13 @@ print-% :
# perform go build on project
go-build : bin/qingcloud-cloud-controller-manager

bin/qingcloud-cloud-controller-manager : $(foreach dir,$(qingcloud-cloud-controller-manager_pkg),$(wildcard $(dir)/*.go)) Makefile
go build -o bin/qingcloud-cloud-controller-manager $(GO_BUILD_FLAGS) $(GIT_REPOSITORY) ./cmd/go
bin/qingcloud-cloud-controller-manager :
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-w" -o bin/manager ./cmd/main.go

bin/.docker-images-build-timestamp : bin/qingcloud-cloud-controller-manager Makefile Dockerfile
docker build -q -t $(DOCKER_IMAGE_NAME):$(IMAGE_LABLE) -t dockerhub.qingcloud.com/$(DOCKER_IMAGE_NAME):$(IMAGE_LABLE) . > bin/.docker-images-build-timestamp

bin/.docker_label : bin/.docker-images-build-timestamp
docker push $(DOCKER_IMAGE_NAME):$(IMAGE_LABLE)
docker push dockerhub.qingcloud.com/$(DOCKER_IMAGE_NAME):$(IMAGE_LABLE)
echo $(DOCKER_IMAGE_NAME):$(IMAGE_LABLE) > bin/.docker_label

install-docker : bin/.docker_label

publish :
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-w" -o bin/manager ./cmd/main.go
publish : test go-build
docker build -t ${IMG} -f deploy/Dockerfile bin/
docker push ${IMG}
clean :
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
qyConfigPath = /etc/qingcloud/config.yaml #青云api密钥存放的位置,必填
zone = ap2a
defaultVxNetForLB = vxnet-lddzg8e #lb的默认vxnet,必填
clusterID = "mycluster" #集群名称,必填
userID = "xxxx" #当前集群API密钥的用户ID(如果需要使用IP自动申请的功能,务必填写此字段)
clusterID = "mycluster" #集群名称,必填,任意字符串,但是必须保证在一个网段内唯一。
```
- 生成api密钥文件,具体的文件样式可参考<https://docs.qingcloud.com/product/cli/#%E6%96%B0%E6%89%8B%E6%8C%87%E5%8D%97>
```
Expand All @@ -28,7 +27,7 @@
```
创建`secret`, `kubectl create secret generic qcsecret --from-file=$secret_file -n kube-system`,替换其中的secret_file为上面生成的密钥地址。

4. 安装yaml,等待安装完成即可
1. 安装yaml,等待安装完成即可
```
kubectl apply -f https://raw.githubusercontent.com/yunify/qingcloud-cloud-controller-manager/master/deploy/kube-cloud-controller-manager.yaml
```
Expand Down
2 changes: 1 addition & 1 deletion deploy/kube-cloud-controller-manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ spec:
- --cloud-config=/etc/kubernetes/qingcloud.conf
- --allocate-node-cidrs=true
- --cluster-cidr=10.244.0.0/16
image: kubespheredev/cloud-controller-manager:v1.3.3
image: kubespheredev/cloud-controller-manager:v1.3.4
imagePullPolicy: Always
name: qingcloud-cloud-controller-manager
resources:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/sirupsen/logrus v1.4.1 // indirect
github.com/spf13/afero v1.2.2 // indirect
github.com/spf13/cobra v0.0.3 // indirect
github.com/yunify/qingcloud-sdk-go v2.0.0-alpha.35+incompatible
github.com/yunify/qingcloud-sdk-go v2.0.0-alpha.35.0.20190513053909-5e6152f06771+incompatible
gopkg.in/gcfg.v1 v1.2.3
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.2.2 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18 h1:MPPkRncZLN9Kh4M
github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/yunify/qingcloud-sdk-go v2.0.0-alpha.35+incompatible h1:KSesALlaxBZ+pX4rTSDPPwl3PXo7m002D1eGOQjFosc=
github.com/yunify/qingcloud-sdk-go v2.0.0-alpha.35+incompatible/go.mod h1:q4o/lbL+PCUIGbzyYzAHsbCgh3bQ/LA7VLFRQTlvrcM=
github.com/yunify/qingcloud-sdk-go v2.0.0-alpha.35.0.20190513053909-5e6152f06771+incompatible h1:Pmj6eGFEzKydhD9nYTbN1C7YQJhVvFu5b86SzpqbTc4=
github.com/yunify/qingcloud-sdk-go v2.0.0-alpha.35.0.20190513053909-5e6152f06771+incompatible/go.mod h1:q4o/lbL+PCUIGbzyYzAHsbCgh3bQ/LA7VLFRQTlvrcM=
go.uber.org/atomic v0.0.0-20181018215023-8dc6146f7569 h1:nSQar3Y0E3VQF/VdZ8PTAilaXpER+d7ypdABCrpwMdg=
go.uber.org/atomic v0.0.0-20181018215023-8dc6146f7569/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/multierr v0.0.0-20180122172545-ddea229ff1df h1:shvkWr0NAZkg4nPuE3XrKP0VuBPijjk3TfX6Y6acFNg=
Expand Down
16 changes: 13 additions & 3 deletions pkg/qingcloud/qingcloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ type Config struct {
Zone string `gcfg:"zone"`
DefaultVxNetForLB string `gcfg:"defaultVxNetForLB"`
ClusterID string `gcfg:"clusterID"`
UserID string `gcfg:"userID"`
}
}

Expand Down Expand Up @@ -109,7 +108,18 @@ func newQingCloud(config Config) (cloudprovider.Interface, error) {
if err != nil {
return nil, err
}

api, _ := qcService.Accesskey(config.Global.Zone)
output, err := api.DescribeAccessKeys(&qcservice.DescribeAccessKeysInput{
AccessKeys: []*string{&qcConfig.AccessKeyID},
})
if err != nil {
klog.Errorf("Failed to get userID")
return nil, err
}
if len(output.AccessKeySet) == 0 {
err = fmt.Errorf("AccessKey %s have not userid", qcConfig.AccessKeyID)
return nil, err
}
qc := QingCloud{
instanceService: instanceService,
lbService: lbService,
Expand All @@ -120,7 +130,7 @@ func newQingCloud(config Config) (cloudprovider.Interface, error) {
zone: config.Global.Zone,
defaultVxNetForLB: config.Global.DefaultVxNetForLB,
clusterID: config.Global.ClusterID,
userID: config.Global.UserID,
userID: *output.AccessKeySet[0].Owner,
}

klog.V(1).Infof("QingCloud provider init done")
Expand Down
96 changes: 96 additions & 0 deletions vendor/github.com/yunify/qingcloud-sdk-go/service/accesskey.go

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

21 changes: 21 additions & 0 deletions vendor/github.com/yunify/qingcloud-sdk-go/service/types.go

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

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

Loading