Skip to content

Commit

Permalink
Merge pull request #71 from krousey/move_repos
Browse files Browse the repository at this point in the history
Reverting the removal of provider specific code
  • Loading branch information
krisnova authored Apr 16, 2018
2 parents a9f06b0 + a38a874 commit 0291e83
Show file tree
Hide file tree
Showing 605 changed files with 1,958,650 additions and 1 deletion.
13 changes: 12 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 cloud/google/cmd/gce-machine-controller/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gce-machine-controller
30 changes: 30 additions & 0 deletions cloud/google/cmd/gce-machine-controller/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# 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 golang:1.10.0 as builder
WORKDIR /go/src/k8s.io/kube-deploy/cluster-api
# This expects that the context passed to the docker build command is
# the cluster-api directory.
# e.g. docker build -t <tag> -f <this_Dockerfile> <path_to_cluster-api>
COPY . .

RUN CGO_ENABLED=0 GOOS=linux go install -a -ldflags '-extldflags "-static"' k8s.io/kube-deploy/cluster-api/cloud/google/cmd/gce-machine-controller

# Final container
FROM alpine:3.7
RUN apk --no-cache add ca-certificates bash

COPY --from=builder /go/bin/gce-machine-controller .

38 changes: 38 additions & 0 deletions cloud/google/cmd/gce-machine-controller/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# 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 push dev_image dev_push fix_gcs_permissions

GCR_BUCKET = k8s-cluster-api
PREFIX = gcr.io/$(GCR_BUCKET)
DEV_PREFIX ?= gcr.io/$(shell gcloud config get-value project)
NAME = gce-machine-controller
TAG = 0.0.3

image:
docker build -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"
69 changes: 69 additions & 0 deletions cloud/google/cmd/gce-machine-controller/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
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 (
"github.com/golang/glog"
"github.com/kubernetes-incubator/apiserver-builder/pkg/controller"
"github.com/spf13/pflag"
corev1 "k8s.io/api/core/v1"
"k8s.io/apiserver/pkg/util/logs"

"sigs.k8s.io/cluster-api/cloud/google"
"sigs.k8s.io/cluster-api/pkg/client/clientset_generated/clientset"
"sigs.k8s.io/cluster-api/pkg/controller/config"
"sigs.k8s.io/cluster-api/pkg/controller/machine"
"sigs.k8s.io/cluster-api/pkg/controller/sharedinformers"
)

var (
kubeadmToken = pflag.String("token", "", "Kubeadm token to use to join new machines")
)

func init() {
config.ControllerConfig.AddFlags(pflag.CommandLine)
}

func main() {
pflag.Parse()

logs.InitLogs()
defer logs.FlushLogs()

config, err := controller.GetConfig(config.ControllerConfig.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)
}

actuator, err := google.NewMachineActuator(*kubeadmToken, client.ClusterV1alpha1().Machines(corev1.NamespaceDefault))
if err != nil {
glog.Fatalf("Could not create Google machine actuator: %v", err)
}

shutdown := make(chan struct{})
si := sharedinformers.NewSharedInformers(config, shutdown)
// If this doesn't compile, the code generator probably
// overwrote the customized NewMachineController function.
c := machine.NewMachineController(config, si, actuator)
c.Run(shutdown)
select {}
}
77 changes: 77 additions & 0 deletions cloud/google/cmd/generate-image/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
Copyright 2017 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 (
"fmt"

"github.com/golang/glog"
"github.com/spf13/cobra"
"sigs.k8s.io/cluster-api/cloud/google"
)

type options struct {
version string
role string
dockerImages []string
}

var opts options

var generateCmd = &cobra.Command{
Use: "generate_image",
Short: "Outputs a script to generate a preloaded image",
Run: func(cmd *cobra.Command, args []string) {
if err := runGenerate(opts); err != nil {
glog.Exit(err)
}
},
}

func init() {
generateCmd.Flags().StringVar(&opts.version, "version", "1.7.3", "The version of kubernetes to install")
generateCmd.Flags().StringVar(&opts.role, "role", "master", "The role of the machine (master or node)")
generateCmd.Flags().StringArrayVar(&opts.dockerImages, "extra-docker-images", []string{}, "extra docker images to preload")
}

func runGenerate(o options) error {
var script string
var err error
switch o.role {
case "master":
script, err = google.PreloadMasterScript(o.version, o.dockerImages)
case "node":
script, err = google.PreloadMasterScript(o.version, o.dockerImages)
default:
return fmt.Errorf("unrecognized role: %q", o.role)
}

if err != nil {
return err
}

// just print the script for now
// TODO actually start a VM, let it run the script, stop the VM, then create the image
fmt.Println(script)
return nil
}

func main() {
if err := generateCmd.Execute(); err != nil {
glog.Exit(err)
}
}
Loading

0 comments on commit 0291e83

Please sign in to comment.