Skip to content

Commit

Permalink
Aligning SampleProvider to Controller based MC
Browse files Browse the repository at this point in the history
  • Loading branch information
prashanth26 committed Jun 3, 2020
1 parent 501261a commit 3704b55
Show file tree
Hide file tree
Showing 24 changed files with 488 additions and 919 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*.DS_Store
*amd64
*.html
main

# Output of the go coverage tool
*coverprofile.out*
20 changes: 16 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
FROM alpine:3.6
############# builder #############
FROM golang:1.13.5 AS builder

RUN apk add --update bash curl
WORKDIR /go/src/github.com/gardener/machine-controller-manager-provider-sampleprovider
COPY . .

COPY bin/rel/cmi-plugin /cmi-plugin
RUN .ci/build

############# base #############
FROM alpine:3.11.2 as base

RUN apk add --update bash curl tzdata
WORKDIR /
ENTRYPOINT ["/cmi-plugin"]

############# machine-controller #############
FROM base AS machine-controller

COPY --from=builder /go/src/github.com/gardener/machine-controller-manager-provider-sampleprovider/bin/rel/machine-controller /machine-controller
ENTRYPOINT ["/machine-controller"]
61 changes: 45 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.

PROVIDER_NAME := SampleProvider
PROJECT_NAME := gardener
BINARY_PATH := bin/
IMAGE_REPOSITORY := docker-repository-link-goes-here
COVERPROFILE := test/output/coverprofile.out
IMAGE_REPOSITORY := <link-to-image-repo>
IMAGE_TAG := $(shell cat VERSION)
PROVIDER_NAME := SampleProvider
PROJECT_NAME := gardener
CONTROL_NAMESPACE := default
CONTROL_KUBECONFIG := dev/target-kubeconfig.yaml
TARGET_KUBECONFIG := dev/target-kubeconfig.yaml

#########################################
# Rules for running helper scripts
Expand All @@ -30,6 +34,27 @@ rename-provider:
rename-project:
@./hack/rename-project ${PROJECT_NAME}

#########################################
# Rules for starting machine-controller locally
#########################################

.PHONY: start
start:
@GO111MODULE=on go run \
-mod=vendor \
cmd/machine-controller/main.go \
--control-kubeconfig=$(CONTROL_KUBECONFIG) \
--target-kubeconfig=$(TARGET_KUBECONFIG) \
--namespace=$(CONTROL_NAMESPACE) \
--machine-creation-timeout=20m \
--machine-drain-timeout=5m \
--machine-health-timeout=10m \
--machine-pv-detach-timeout=2m \
--machine-safety-apiserver-statuscheck-timeout=30s \
--machine-safety-apiserver-statuscheck-period=1m \
--machine-safety-orphan-vms-period=30m \
--v=3

#########################################
# Rules for re-vendoring
#########################################
Expand All @@ -43,42 +68,46 @@ revendor:
update-dependencies:
@env GO111MODULE=on go get -u

#########################################
# Rules for testing
#########################################

.PHONY: test-unit
test-unit:
.ci/test

#########################################
# Rules for build/release
#########################################

.PHONY: release
release: build-local build docker-image docker-push rename-binaries
release: build-local build docker-image docker-login docker-push rename-binaries

.PHONY: build-local
build-local:
go build \
-v \
-o ${BINARY_PATH}/cmi-plugin \
app/controller/cmi-plugin.go
@env LOCAL_BUILD=1 .ci/build

.PHONY: build
build:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-a \
-v \
-o ${BINARY_PATH}/rel/cmi-plugin \
app/controller/cmi-plugin.go
@.ci/build

.PHONY: docker-image
docker-image:
@if [[ ! -f ${BINARY_PATH}/rel/cmi-plugin ]]; then echo "No binary found. Please run 'make build'"; false; fi
@docker build -t $(IMAGE_REPOSITORY):$(IMAGE_TAG) .

.PHONY: docker-login
docker-login:
@gcloud auth login

.PHONY: docker-push
docker-push:
@if ! docker images $(IMAGE_REPOSITORY) | awk '{ print $$2 }' | grep -q -F $(IMAGE_TAG); then echo "$(IMAGE_REPOSITORY) version $(IMAGE_TAG) is not yet built. Please run 'make docker-images'"; false; fi
@gcloud docker -- push $(IMAGE_REPOSITORY):$(IMAGE_TAG)

.PHONY: rename-binaries
rename-binaries:
@if [[ -f bin/cmi-plugin ]]; then cp bin/cmi-plugin cmi-plugin-darwin-amd64; fi
@if [[ -f bin/rel/cmi-plugin ]]; then cp bin/rel/cmi-plugin cmi-plugin-linux-amd64; fi
@if [[ -f bin/machine-controller ]]; then cp bin/machine-controller machine-controller-darwin-amd64; fi
@if [[ -f bin/rel/machine-controller ]]; then cp bin/rel/machine-controller machine-controller-linux-amd64; fi

.PHONY: clean
clean:
Expand Down
13 changes: 13 additions & 0 deletions NOTICE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@ Copyright (c) 2018-2019 SAP SE or an SAP affiliate company. All rights reserved.

## Seed Source

### Current

The current seed source code is derived from the Machine Controller Manager repo under the Gardener project.

Machine Controller Manager
Copyright 2020 The Machine Controller Manager Authors.
https://github.com/gardener/machine-controller-manager/releases/tag/v0.29.0
https://github.com/gardener/machine-controller-manager/blob/v0.29.0/LICENSE.md

This project however is inturn derived from several smaller kubernetes/kubernetes pieces. Refer [here](https://github.com/gardener/machine-controller-manager/blob/v0.29.0/NOTICE.md)

### Deprecated

The source code of this component was seeded based on a copy of the following files from container-storage-interface/spec.

Container Storage Interface (CSI) Drivers
Expand Down
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
# machine-controller-manager-provider-sampleprovider
Out of tree (gRPC based) implementation for `SampleProvider` as a new provider.
Out of tree (controller based) implementation for `SampleProvider` as a new provider.

## About
- This is a sample repository that provides the blueprint required to implement a new (hyperscale) provider. We call the new provider as `SampleProvider` for our ease.
- Each provider (plugin/actuator/driver) is a gRPC server and implements the services defined at [machine-spec](https://github.com/gardener/machine-spec).
- Each provider implements the interface defined at [MCM OOT driver](https://github.com/gardener/machine-controller-manager/blob/master/pkg/util/provider/driver/driver.go).

## Fundamental Design Principles:
Following are the basic principles kept in mind while developing the external plugin.
* Communication between external plugin and machine-controller is achieved using gRPC mechanism.
* External plugin behaves as gRPC-server and machine-controller behaves as gRPC client.
* Cloud-provider specific contract should be scoped under `ProviderSpec` field. `ProviderSpec` field is expected to be raw-bytes at machine-controller-side. External plugin should have pre-defined typed-apis to parse the `ProviderSpec` to make necessary CP specific calls.
* External plugins do not need to communicate with kubernetes api-server.
* Kubeconfig may not be available to external-plugins.
* Communication between this Machine Controller (MC) and Machine Controller Manager (MCM) is achieved using the Kubernetes native declarative approach.
* Machine Controller (MC) behaves as the controller used to interact with the cloud provider and manage the VMs corresponding to the machine objects.
* Machine Controller Manager (MCM) deals with higher level objects such as machine-set and machine-deployment objects.

## Support for a new provider
- Steps to be followed while implementing a new provider are mentioned [here](https://github.com/gardener/machine-controller-manager/blob/cmi-client/docs/development/new_cp_support.md)
- Steps to be followed while implementing a new provider are mentioned [here](https://github.com/gardener/machine-controller-manager/blob/master/docs/development/cp_support_new.md)
69 changes: 0 additions & 69 deletions app/controller/cmi-plugin.go

This file was deleted.

56 changes: 56 additions & 0 deletions cmd/machine-controller/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
Copyright 2014 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.
This file was copied and modified from the kubernetes/kubernetes project
https://github.com/kubernetes/kubernetes/release-1.8/cmd/kube-controller-manager/controller_manager.go
Modifications Copyright (c) 2017 SAP SE or an SAP affiliate company. All rights reserved.
*/

package main

import (
"fmt"
"os"

cp "github.com/gardener/machine-controller-manager-provider-sampleprovider/pkg/provider"
"github.com/gardener/machine-controller-manager-provider-sampleprovider/pkg/spi"
_ "github.com/gardener/machine-controller-manager/pkg/util/client/metrics/prometheus" // for client metric registration
"github.com/gardener/machine-controller-manager/pkg/util/provider/app"
"github.com/gardener/machine-controller-manager/pkg/util/provider/app/options"
_ "github.com/gardener/machine-controller-manager/pkg/util/reflector/prometheus" // for reflector metric registration
_ "github.com/gardener/machine-controller-manager/pkg/util/workqueue/prometheus" // for workqueue metric registration
"github.com/spf13/pflag"
"k8s.io/component-base/cli/flag"
"k8s.io/component-base/logs"
)

func main() {

s := options.NewMCServer()
s.AddFlags(pflag.CommandLine)

flag.InitFlags()
logs.InitLogs()
defer logs.FlushLogs()

provider := cp.NewProvider(&spi.PluginSPIImpl{})

if err := app.Run(s, provider); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}

}
Loading

0 comments on commit 3704b55

Please sign in to comment.