Skip to content

Commit

Permalink
Merge pull request kubernetes-sigs#307 from akutz/feature/kubeadm-boo…
Browse files Browse the repository at this point in the history
…tstrap

Support for kubeadm bootstrapping & using new imgs
  • Loading branch information
k8s-ci-robot authored Jun 19, 2019
2 parents 5239208 + e933693 commit 9772d2d
Show file tree
Hide file tree
Showing 193 changed files with 10,477 additions and 7,066 deletions.
123 changes: 62 additions & 61 deletions cmd/clusterctl/examples/vsphere/generate-yaml.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ CLUSTER_GENERATED_FILE=${OUTPUT_DIR}/cluster.yaml
ADDON_TEMPLATE_FILE=${TEMPLATE_DIR}/addons.yaml.template
ADDON_GENERATED_FILE=${OUTPUT_DIR}/addons.yaml

CLUSTER_API_CRD_PATH=./vendor/sigs.k8s.io/cluster-api/config
CLUSTER_API_CRD_PATH=./config/cluster-api
VSPHERE_CLUSTER_API_CRD_PATH=./config

PROVIDERCOMPONENT_GENERATED_FILE=${OUTPUT_DIR}/provider-components.yaml
Expand Down Expand Up @@ -116,65 +116,66 @@ export VSPHERE_DISK=${VSPHERE_DISK:-}
export VSPHERE_DISK_SIZE_GB=${VSPHERE_DISK_SIZE_GB:-20}

# validate all required variables before generating any files

if [ -z "${VSPHERE_USER}" ]; then
echo "env var VSPHERE_USER is required" 1>&2
exit 1
fi

if [ -z "${VSPHERE_PASSWORD}" ]; then
echo "env var VSPHERE_PASSWORD is required" 1>&2
exit 1
fi

if [ -z "${VSPHERE_SERVER}" ]; then
echo "env var VSPHERE_SERVER is required" 1>&2
exit 1
fi

if [ -z "${CAPV_MANAGER_IMAGE}" ]; then
echo "env var CAPV_MANAGER_IMAGE is required" 1>&2
exit 1
fi

if [ -z "${VSPHERE_DATACENTER}" ]; then
echo "env var VSPHERE_DATACENTER is required" 1>&2
exit 1
fi

if [ -z "${VSPHERE_DATASTORE}" ]; then
echo "env var VSPHERE_DATASTORE is required" 1>&2
exit 1
fi

if [ -z "${VSPHERE_NETWORK}" ]; then
echo "env var VSPHERE_NETWORK is required" 1>&2
exit 1
fi

if [ -z "${VSPHERE_RESOURCE_POOL}" ]; then
echo "env var VSPHERE_RESOURCE_POOL is required" 1>&2
exit 1
fi

if [ -z "${VSPHERE_FOLDER}" ]; then
echo "env var VSPHERE_FOLDER is required" 1>&2
exit 1
fi

if [ -z "${VSPHERE_TEMPLATE}" ]; then
echo "env var VSPHERE_TEMPLATE is required" 1>&2
exit 1
fi

if [ -z "${VSPHERE_DISK}" ]; then
echo "env var VSPHERE_DISK is required" 1>&2
exit 1
fi

if [ ${VSPHERE_DISK_SIZE_GB} -lt 20 ]; then
echo "env var VSPHERE_DISK_SIZE_GB must be >= 20" 1>&2
exit 1
if [ ! "${CAPV_YAML_VALIDATION:-1}" = "0" ]; then
if [ -z "${VSPHERE_USER}" ]; then
echo "env var VSPHERE_USER is required" 1>&2
exit 1
fi

if [ -z "${VSPHERE_PASSWORD}" ]; then
echo "env var VSPHERE_PASSWORD is required" 1>&2
exit 1
fi

if [ -z "${VSPHERE_SERVER}" ]; then
echo "env var VSPHERE_SERVER is required" 1>&2
exit 1
fi

if [ -z "${CAPV_MANAGER_IMAGE}" ]; then
echo "env var CAPV_MANAGER_IMAGE is required" 1>&2
exit 1
fi

if [ -z "${VSPHERE_DATACENTER}" ]; then
echo "env var VSPHERE_DATACENTER is required" 1>&2
exit 1
fi

if [ -z "${VSPHERE_DATASTORE}" ]; then
echo "env var VSPHERE_DATASTORE is required" 1>&2
exit 1
fi

if [ -z "${VSPHERE_NETWORK}" ]; then
echo "env var VSPHERE_NETWORK is required" 1>&2
exit 1
fi

if [ -z "${VSPHERE_RESOURCE_POOL}" ]; then
echo "env var VSPHERE_RESOURCE_POOL is required" 1>&2
exit 1
fi

if [ -z "${VSPHERE_FOLDER}" ]; then
echo "env var VSPHERE_FOLDER is required" 1>&2
exit 1
fi

if [ -z "${VSPHERE_TEMPLATE}" ]; then
echo "env var VSPHERE_TEMPLATE is required" 1>&2
exit 1
fi

if [ -z "${VSPHERE_DISK}" ]; then
echo "env var VSPHERE_DISK is required" 1>&2
exit 1
fi

if [ "${VSPHERE_DISK_SIZE_GB}" -lt "20" ]; then
echo "env var VSPHERE_DISK_SIZE_GB must be >= 20" 1>&2
exit 1
fi
fi

envsubst < $MACHINE_TEMPLATE_FILE > "${MACHINE_GENERATED_FILE}"
Expand Down Expand Up @@ -207,7 +208,7 @@ MACHINE_CONTROLLER_SSH_PRIVATE=$(cat $MACHINE_CONTROLLER_SSH_HOME$MACHINE_CONTRO

kustomize build $VSPHERE_CLUSTER_API_CRD_PATH/default/ > $PROVIDERCOMPONENT_GENERATED_FILE
echo "---" >> $PROVIDERCOMPONENT_GENERATED_FILE
kustomize build $CLUSTER_API_CRD_PATH/default/ >> $PROVIDERCOMPONENT_GENERATED_FILE
kustomize build $CLUSTER_API_CRD_PATH/ >> $PROVIDERCOMPONENT_GENERATED_FILE

echo "Done generating $PROVIDERCOMPONENT_GENERATED_FILE"

Expand Down
10 changes: 8 additions & 2 deletions cmd/clusterctl/main.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
/*
Copyright 2018 The Kubernetes Authors.
Copyright 2019 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.
Expand All @@ -14,10 +17,13 @@ limitations under the License.
package main

import (
_ "sigs.k8s.io/cluster-api-provider-vsphere/pkg/cloud/vsphere"
"sigs.k8s.io/cluster-api/cmd/clusterctl/cmd"
"sigs.k8s.io/cluster-api/pkg/apis/cluster/common"

"sigs.k8s.io/cluster-api-provider-vsphere/pkg/deployer"
)

func main() {
common.RegisterClusterProvisioner("vsphere", deployer.Deployer{})
cmd.Execute()
}
89 changes: 63 additions & 26 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2018 The Kubernetes Authors.
Copyright 2019 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.
Expand All @@ -18,38 +18,45 @@ package main

import (
"flag"
"net/http"
"net/http/pprof"
"time"

"github.com/spf13/pflag"
"github.com/pkg/errors"
corev1 "k8s.io/client-go/kubernetes/typed/core/v1"
"k8s.io/klog"

"sigs.k8s.io/cluster-api-provider-vsphere/pkg/apis"
"sigs.k8s.io/cluster-api-provider-vsphere/pkg/controller"
clusterapis "sigs.k8s.io/cluster-api/pkg/apis"
"sigs.k8s.io/cluster-api/pkg/apis/cluster/common"
"sigs.k8s.io/cluster-api/pkg/client/clientset_generated/clientset"
capicluster "sigs.k8s.io/cluster-api/pkg/controller/cluster"
capimachine "sigs.k8s.io/cluster-api/pkg/controller/machine"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/runtime/signals"
)

var (
namedMachinesPath = pflag.String("namedmachines", "", "path to named machines yaml file")
"sigs.k8s.io/cluster-api-provider-vsphere/pkg/apis"
"sigs.k8s.io/cluster-api-provider-vsphere/pkg/cloud/vsphere/actuators/cluster"
"sigs.k8s.io/cluster-api-provider-vsphere/pkg/cloud/vsphere/actuators/machine"
"sigs.k8s.io/cluster-api-provider-vsphere/pkg/record"
)

func main() {
klog.InitFlags(nil)
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
pflag.Set("logtostderr", "true")
watchNamespace := pflag.String("namespace", "",
flag.Set("logtostderr", "true")
watchNamespace := flag.String("namespace", "",
"Namespace that the controller watches to reconcile cluster-api objects. If unspecified, the controller watches for cluster-api objects across all namespaces.")
pflag.Parse()
profilerAddr := flag.String("profiler-address", "", "the address to expose the pprof profiler")

// Get a config to talk to the apiserver
cfg, err := config.GetConfig()
if err != nil {
klog.Fatalf("Failed to get config: %s", err.Error())
flag.Parse()

if addr := *profilerAddr; addr != "" {
go runProfiler(addr)
}

syncPeriod := 120 * time.Second
cfg := config.GetConfigOrDie()

// Setup a Manager
syncPeriod := 10 * time.Minute
opts := manager.Options{
SyncPeriod: &syncPeriod,
}
Expand All @@ -59,13 +66,33 @@ func main() {
klog.Infof("Watching cluster-api objects only in namespace %q for reconciliation.", opts.Namespace)
}

// Create a new Cmd to provide shared dependencies and start components
mgr, err := manager.New(cfg, opts)
if err != nil {
klog.Fatal(err)
klog.Fatalf("Failed to set up overall controller manager: %v", err)
}

cs, err := clientset.NewForConfig(cfg)
if err != nil {
klog.Fatalf("Failed to create client from configuration: %v", err)
}

// Setup Scheme for all resources
coreClient, err := corev1.NewForConfig(cfg)
if err != nil {
klog.Fatalf("Failed to create corev1 client from configuration: %v", err)
}

// Initialize event recorder.
record.InitFromRecorder(mgr.GetRecorder("vsphere-controller"))

// Initialize cluster actuator.
clusterActuator := cluster.NewActuator(cs.ClusterV1alpha1(), coreClient)

// Initialize machine actuator.
machineActuator := machine.NewActuator(cs.ClusterV1alpha1(), coreClient)

// Register the cluster actuator as the deployer.
common.RegisterClusterProvisioner("vsphere", clusterActuator)

if err := apis.AddToScheme(mgr.GetScheme()); err != nil {
klog.Fatal(err)
}
Expand All @@ -74,13 +101,23 @@ func main() {
klog.Fatal(err)
}

// Setup all Controllers
if err := controller.AddToManager(mgr); err != nil {
klog.Fatal(err)
capimachine.AddWithActuator(mgr, machineActuator)
capicluster.AddWithActuator(mgr, clusterActuator)

if err := mgr.Start(signals.SetupSignalHandler()); err != nil {
klog.Fatalf("Failed to run manager: %v", err)
}
}

klog.Info("Starting the Cmd.")
func runProfiler(addr string) {
mux := http.NewServeMux()
mux.HandleFunc("/debug/pprof/", pprof.Index)
mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
mux.HandleFunc("/debug/pprof/trace", pprof.Trace)

// Start the Cmd
klog.Fatal(mgr.Start(signals.SetupSignalHandler()))
if err := http.ListenAndServe(addr, mux); err != nil {
klog.Error(errors.Wrap(err, "error running pprof"))
}
}
22 changes: 22 additions & 0 deletions config/cluster-api/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# This file is copied from sigs.k8s.io/cluster-api/config/default/
# so that we can override the manager image patch file.
# We need to ensure this kustomize config matches
# the config in sigs.k8s.io/cluster-api/config/default/kustomization.yaml

# Adds namespace to all resources.
namespace: cluster-api-system

# Value of this field is prepended to the
# names of all resources, e.g. a deployment named
# "wordpress" becomes "alices-wordpress".
# Note that it should also match with the prefix (text before '-') of the namespace
# field above.
namePrefix: cluster-api-

bases:
- ../../vendor/sigs.k8s.io/cluster-api/config/crds/
- ../../vendor/sigs.k8s.io/cluster-api/config/rbac/
- ../../vendor/sigs.k8s.io/cluster-api/config/manager/

patches:
- manager_image_patch.yaml
11 changes: 11 additions & 0 deletions config/cluster-api/manager_image_patch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: controller-manager
namespace: system
spec:
template:
spec:
containers:
- image: gcr.io/k8s-cluster-api/cluster-api-controller:0.1.3
name: manager
2 changes: 2 additions & 0 deletions config/crds/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
resources:
- vsphereproviderconfig_v1alpha1_vsphereclusterproviderconfig.yaml
- vsphereproviderconfig_v1alpha1_vspheremachineproviderconfig.yaml
- vsphereproviderconfig_v1alpha1_vsphereclusterproviderstatus.yaml
- vsphereproviderconfig_v1alpha1_vspheremachineproviderstatus.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
creationTimestamp: null
labels:
controller-tools.k8s.io: "1.0"
name: vsphereclusterproviderstatuses.vsphereproviderconfig.sigs.k8s.io
spec:
group: vsphereproviderconfig.sigs.k8s.io
names:
kind: VsphereClusterProviderStatus
plural: vsphereclusterproviderstatuses
scope: Namespaced
validation:
openAPIV3Schema:
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds'
type: string
metadata:
type: object
ready:
type: boolean
version: v1alpha1
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
Loading

0 comments on commit 9772d2d

Please sign in to comment.