diff --git a/Makefile b/Makefile index 8cb1756210..76ad19d786 100644 --- a/Makefile +++ b/Makefile @@ -71,7 +71,6 @@ bin: .PHONY: build build: ## build binary - $(DOCKER_CMD) go install $(GOGCFLAGS) -ldflags '-extldflags "-static"' sigs.k8s.io/cluster-api-provider-aws/cmd/cluster-controller $(DOCKER_CMD) go install $(GOGCFLAGS) -ldflags '-extldflags "-static"' sigs.k8s.io/cluster-api-provider-aws/cmd/machine-controller aws-actuator: diff --git a/cmd/cluster-controller/Dockerfile b/cmd/cluster-controller/Dockerfile deleted file mode 100644 index 5a77d18611..0000000000 --- a/cmd/cluster-controller/Dockerfile +++ /dev/null @@ -1,29 +0,0 @@ -# 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. - -# Reproducible builder image -FROM openshift/origin-release:golang-1.10 as builder -WORKDIR /go/src/sigs.k8s.io/cluster-api-provider-aws -# This expects that the context passed to the docker build command is -# the cluster-api-provider-aws directory. -# e.g. docker build -t -f -COPY . . - -RUN CGO_ENABLED=0 GOOS=linux go install -ldflags '-extldflags "-static"' sigs.k8s.io/cluster-api-provider-aws/cmd/cluster-controller - -# Final container -FROM openshift/origin-base -RUN yum install -y ca-certificates openssh - -COPY --from=builder /go/bin/cluster-controller . diff --git a/cmd/cluster-controller/Makefile b/cmd/cluster-controller/Makefile deleted file mode 100644 index eaef2680d6..0000000000 --- a/cmd/cluster-controller/Makefile +++ /dev/null @@ -1,38 +0,0 @@ -# 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. - -.PHONY: image - -GCR_BUCKET = k8s-cluster-api -PREFIX = gcr.io/$(GCR_BUCKET) -DEV_PREFIX ?= gcr.io/$(shell gcloud config get-value project) -NAME = aws-cluster-controller -TAG = 0.0.1 - -image: - imagebuilder -t "$(PREFIX)/$(NAME):$(TAG)" -f ./Dockerfile ../.. - -push: image - docker push "$(PREFIX)/$(NAME):$(TAG)" - $(MAKE) fix_gcs_permissions - -fix_gcs_permissions: - gsutil acl ch -u AllUsers:READ gs://artifacts.$(GCR_BUCKET).appspot.com - gsutil -m acl ch -r -u AllUsers:READ gs://artifacts.$(GCR_BUCKET).appspot.com - -dev_image: - docker build -t "$(DEV_PREFIX)/$(NAME):$(TAG)-dev" -f ./Dockerfile ../.. - -dev_push: dev_image - docker push "$(DEV_PREFIX)/$(NAME):$(TAG)-dev" diff --git a/cmd/cluster-controller/main.go b/cmd/cluster-controller/main.go deleted file mode 100644 index 0e34b616ba..0000000000 --- a/cmd/cluster-controller/main.go +++ /dev/null @@ -1,47 +0,0 @@ -/* -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 main - -import ( - "flag" - - "github.com/golang/glog" - "github.com/spf13/pflag" - "k8s.io/apiserver/pkg/util/logs" - "sigs.k8s.io/cluster-api/pkg/controller/config" - - "sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/aws/controllers/cluster" - "sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/aws/controllers/cluster/options" -) - -func init() { - config.ControllerConfig.AddFlags(pflag.CommandLine) -} - -func main() { - // the following line exists to make glog happy, for more information, see: https://github.com/kubernetes/kubernetes/issues/17162 - flag.CommandLine.Parse([]string{}) - pflag.Parse() - - logs.InitLogs() - defer logs.FlushLogs() - - clusterServer := options.NewServer() - if err := cluster.Run(clusterServer); err != nil { - glog.Errorf("Failed to start cluster controller. Err: %v", err) - } -} diff --git a/pkg/cloud/aws/controllers/cluster/controller.go b/pkg/cloud/aws/controllers/cluster/controller.go deleted file mode 100644 index 0209712994..0000000000 --- a/pkg/cloud/aws/controllers/cluster/controller.go +++ /dev/null @@ -1,159 +0,0 @@ -/* -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 cluster - -import ( - "os" - - "github.com/golang/glog" - "github.com/kubernetes-incubator/apiserver-builder/pkg/controller" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/util/uuid" - "k8s.io/client-go/kubernetes" - v1core "k8s.io/client-go/kubernetes/typed/core/v1" - "k8s.io/client-go/rest" - "k8s.io/client-go/tools/leaderelection" - "k8s.io/client-go/tools/leaderelection/resourcelock" - "k8s.io/client-go/tools/record" - "sigs.k8s.io/cluster-api/pkg/client/clientset_generated/clientset" - clusterapiclientsetscheme "sigs.k8s.io/cluster-api/pkg/client/clientset_generated/clientset/scheme" - "sigs.k8s.io/cluster-api/pkg/controller/cluster" - "sigs.k8s.io/cluster-api/pkg/controller/config" - "sigs.k8s.io/cluster-api/pkg/controller/sharedinformers" - - clusteractuator "sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/aws/actuators/cluster" - "sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/aws/controllers/cluster/options" -) - -const ( - controllerName = "aws-cluster-controller" -) - -// Start starts the cluster controller -func Start(server *options.Server, shutdown <-chan struct{}) { - config, err := controller.GetConfig(server.CommonConfig.Kubeconfig) - if err != nil { - glog.Fatalf("Could not create Config for talking to the apiserver: %v", err) - } - - client, err := clientset.NewForConfig(config) - if err != nil { - glog.Fatalf("Could not create client for talking to the apiserver: %v", err) - } - - params := clusteractuator.ActuatorParams{ - ClusterClient: client.ClusterV1alpha1().Clusters(corev1.NamespaceDefault), - } - actuator, err := clusteractuator.NewActuator(params) - if err != nil { - glog.Fatalf("Could not create aws cluster actuator: %v", err) - } - - si := sharedinformers.NewSharedInformers(config, shutdown) - c := cluster.NewClusterController(config, si, actuator) - c.RunAsync(shutdown) - - select {} -} - -// Run runs the cluster controller -func Run(server *options.Server) error { - kubeConfig, err := controller.GetConfig(server.CommonConfig.Kubeconfig) - if err != nil { - glog.Errorf("Could not create Config for talking to the apiserver: %v", err) - return err - } - - kubeClientControl, err := kubernetes.NewForConfig( - rest.AddUserAgent(kubeConfig, "cluster-controller-manager"), - ) - if err != nil { - glog.Errorf("Invalid API configuration for kubeconfig-control: %v", err) - return err - } - - recorder, err := createRecorder(kubeClientControl) - if err != nil { - glog.Errorf("Could not create event recorder : %v", err) - return err - } - - // run function will block and never return. - run := func(stop <-chan struct{}) { - Start(server, stop) - } - - leaderElectConfig := config.GetLeaderElectionConfig() - if !leaderElectConfig.LeaderElect { - run(make(<-chan (struct{}))) - } - - // Identity used to distinguish between multiple cluster controller instances. - id, err := os.Hostname() - if err != nil { - return err - } - - leaderElectionClient := kubernetes.NewForConfigOrDie(rest.AddUserAgent(kubeConfig, "cluster-leader-election")) - - id = id + "-" + string(uuid.NewUUID()) - // Lock required for leader election - rl, err := resourcelock.New( - leaderElectConfig.ResourceLock, - metav1.NamespaceSystem, - controllerName, - leaderElectionClient.CoreV1(), - resourcelock.ResourceLockConfig{ - Identity: id + "-" + controllerName, - EventRecorder: recorder, - }) - if err != nil { - return err - } - - // Try and become the leader and start cluster controller loops - leaderelection.RunOrDie(leaderelection.LeaderElectionConfig{ - Lock: rl, - LeaseDuration: leaderElectConfig.LeaseDuration.Duration, - RenewDeadline: leaderElectConfig.RenewDeadline.Duration, - RetryPeriod: leaderElectConfig.RetryPeriod.Duration, - Callbacks: leaderelection.LeaderCallbacks{ - OnStartedLeading: run, - OnStoppedLeading: func() { - glog.Fatalf("leaderelection lost") - }, - }, - }) - panic("unreachable") -} - -func createRecorder(kubeClient *kubernetes.Clientset) (record.EventRecorder, error) { - - eventsScheme := runtime.NewScheme() - if err := corev1.AddToScheme(eventsScheme); err != nil { - return nil, err - } - // We also emit events for our own types - clusterapiclientsetscheme.AddToScheme(eventsScheme) - - eventBroadcaster := record.NewBroadcaster() - eventBroadcaster.StartLogging(glog.Infof) - eventBroadcaster.StartRecordingToSink(&v1core.EventSinkImpl{Interface: v1core.New(kubeClient.CoreV1().RESTClient()).Events("")}) - return eventBroadcaster.NewRecorder(eventsScheme, corev1.EventSource{Component: controllerName}), nil -} diff --git a/pkg/cloud/aws/controllers/cluster/options/options.go b/pkg/cloud/aws/controllers/cluster/options/options.go deleted file mode 100644 index 34cc57a3e8..0000000000 --- a/pkg/cloud/aws/controllers/cluster/options/options.go +++ /dev/null @@ -1,34 +0,0 @@ -/* -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 options - -import ( - "sigs.k8s.io/cluster-api/pkg/controller/config" -) - -// Server type with server configuration -type Server struct { - CommonConfig *config.Configuration -} - -// NewServer builds a service configuration -func NewServer() *Server { - s := Server{ - CommonConfig: &config.ControllerConfig, - } - return &s -} diff --git a/pkg/cloud/aws/controllers/machine/controller.go b/pkg/cloud/aws/controllers/machine/controller.go deleted file mode 100644 index 3ec8ca4492..0000000000 --- a/pkg/cloud/aws/controllers/machine/controller.go +++ /dev/null @@ -1,170 +0,0 @@ -/* -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 machine - -import ( - "os" - - "github.com/golang/glog" - "github.com/kubernetes-incubator/apiserver-builder/pkg/controller" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/util/uuid" - "k8s.io/client-go/kubernetes" - v1core "k8s.io/client-go/kubernetes/typed/core/v1" - "k8s.io/client-go/rest" - "k8s.io/client-go/tools/leaderelection" - "k8s.io/client-go/tools/leaderelection/resourcelock" - "k8s.io/client-go/tools/record" - "sigs.k8s.io/cluster-api/pkg/client/clientset_generated/clientset" - clusterapiclientsetscheme "sigs.k8s.io/cluster-api/pkg/client/clientset_generated/clientset/scheme" - "sigs.k8s.io/cluster-api/pkg/controller/config" - machinecontroller "sigs.k8s.io/cluster-api/pkg/controller/machine" - "sigs.k8s.io/cluster-api/pkg/controller/sharedinformers" - - machineactuator "sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/aws/actuators/machine" - "sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/aws/controllers/machine/options" - - log "github.com/sirupsen/logrus" - awsclient "sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/aws/client" -) - -const ( - controllerName = "aws-machine-controller" -) - -// Start starts the server -func Start(server *options.Server, shutdown <-chan struct{}) { - config, err := controller.GetConfig(server.CommonConfig.Kubeconfig) - if err != nil { - glog.Fatalf("Could not create Config for talking to the apiserver: %v", err) - } - - client, err := clientset.NewForConfig(config) - if err != nil { - glog.Fatalf("Could not create client for talking to the apiserver: %v", err) - } - - kubeClient, err := kubernetes.NewForConfig(config) - if err != nil { - glog.Fatalf("Could not create kubernetes client to talk to the apiserver: %v", err) - } - - params := machineactuator.ActuatorParams{ - ClusterClient: client, - KubeClient: kubeClient, - AwsClientBuilder: awsclient.NewClient, - Logger: log.WithField("controller", controllerName), - } - actuator, err := machineactuator.NewActuator(params) - if err != nil { - glog.Fatalf("Could not create aws machine actuator: %v", err) - } - - si := sharedinformers.NewSharedInformers(config, shutdown) - c := machinecontroller.NewMachineController(config, si, actuator) - c.RunAsync(shutdown) - - select {} -} - -// Run runs the server -func Run(server *options.Server) error { - kubeConfig, err := controller.GetConfig(server.CommonConfig.Kubeconfig) - if err != nil { - glog.Errorf("Could not create Config for talking to the apiserver: %v", err) - return err - } - - kubeClientControl, err := kubernetes.NewForConfig( - rest.AddUserAgent(kubeConfig, "machine-controller-manager"), - ) - if err != nil { - glog.Errorf("Invalid API configuration for kubeconfig-control: %v", err) - return err - } - - recorder, err := createRecorder(kubeClientControl) - if err != nil { - glog.Errorf("Could not create event recorder : %v", err) - return err - } - - // run function will block and never return. - run := func(stop <-chan struct{}) { - Start(server, stop) - } - - leaderElectConfig := config.GetLeaderElectionConfig() - if !leaderElectConfig.LeaderElect { - run(make(<-chan (struct{}))) - } - - // Identity used to distinguish between multiple machine controller instances. - id, err := os.Hostname() - if err != nil { - return err - } - - leaderElectionClient := kubernetes.NewForConfigOrDie(rest.AddUserAgent(kubeConfig, "machine-leader-election")) - - id = id + "-" + string(uuid.NewUUID()) - // Lock required for leader election - rl, err := resourcelock.New( - leaderElectConfig.ResourceLock, - metav1.NamespaceSystem, - controllerName, - leaderElectionClient.CoreV1(), - resourcelock.ResourceLockConfig{ - Identity: id + "-" + controllerName, - EventRecorder: recorder, - }) - if err != nil { - return err - } - - // Try and become the leader and start machine controller loops - leaderelection.RunOrDie(leaderelection.LeaderElectionConfig{ - Lock: rl, - LeaseDuration: leaderElectConfig.LeaseDuration.Duration, - RenewDeadline: leaderElectConfig.RenewDeadline.Duration, - RetryPeriod: leaderElectConfig.RetryPeriod.Duration, - Callbacks: leaderelection.LeaderCallbacks{ - OnStartedLeading: run, - OnStoppedLeading: func() { - glog.Fatalf("leaderelection lost") - }, - }, - }) - panic("unreachable") -} - -func createRecorder(kubeClient *kubernetes.Clientset) (record.EventRecorder, error) { - - eventsScheme := runtime.NewScheme() - if err := corev1.AddToScheme(eventsScheme); err != nil { - return nil, err - } - // We also emit events for our own types - clusterapiclientsetscheme.AddToScheme(eventsScheme) - - eventBroadcaster := record.NewBroadcaster() - eventBroadcaster.StartLogging(glog.Infof) - eventBroadcaster.StartRecordingToSink(&v1core.EventSinkImpl{Interface: v1core.New(kubeClient.CoreV1().RESTClient()).Events("")}) - return eventBroadcaster.NewRecorder(eventsScheme, corev1.EventSource{Component: controllerName}), nil -} diff --git a/pkg/cloud/aws/controllers/machine/options/options.go b/pkg/cloud/aws/controllers/machine/options/options.go deleted file mode 100644 index e7b7d19cfe..0000000000 --- a/pkg/cloud/aws/controllers/machine/options/options.go +++ /dev/null @@ -1,34 +0,0 @@ -/* -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 options - -import ( - "sigs.k8s.io/cluster-api/pkg/controller/config" -) - -// Server type with server configuration -type Server struct { - CommonConfig *config.Configuration -} - -// NewServer builds a server configuration -func NewServer() *Server { - s := Server{ - CommonConfig: &config.ControllerConfig, - } - return &s -}