forked from kubernetes-sigs/cluster-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integration test with example provider (kubernetes-sigs#755)
This is the skeleton for the integration test with example provider
- Loading branch information
1 parent
6ea4182
commit d4d6eaf
Showing
23 changed files
with
494 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") | ||
|
||
go_library( | ||
name = "go_default_library", | ||
srcs = ["main.go"], | ||
importpath = "sigs.k8s.io/cluster-api/cmd/example-provider", | ||
visibility = ["//visibility:private"], | ||
deps = [ | ||
"//pkg/apis:go_default_library", | ||
"//pkg/apis/cluster/common:go_default_library", | ||
"//pkg/client/clientset_generated/clientset:go_default_library", | ||
"//pkg/controller/cluster:go_default_library", | ||
"//pkg/controller/machine:go_default_library", | ||
"//pkg/provider/example/actuators/cluster:go_default_library", | ||
"//pkg/provider/example/actuators/machine:go_default_library", | ||
"//vendor/k8s.io/klog:go_default_library", | ||
"//vendor/sigs.k8s.io/controller-runtime/pkg/client/config:go_default_library", | ||
"//vendor/sigs.k8s.io/controller-runtime/pkg/manager:go_default_library", | ||
"//vendor/sigs.k8s.io/controller-runtime/pkg/runtime/signals:go_default_library", | ||
], | ||
) | ||
|
||
go_binary( | ||
name = "example-provider", | ||
embed = [":go_default_library"], | ||
visibility = ["//visibility:public"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
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. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"flag" | ||
|
||
"k8s.io/klog" | ||
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/cluster-api/pkg/provider/example/actuators/cluster" | ||
"sigs.k8s.io/cluster-api/pkg/provider/example/actuators/machine" | ||
"sigs.k8s.io/controller-runtime/pkg/client/config" | ||
"sigs.k8s.io/controller-runtime/pkg/manager" | ||
"sigs.k8s.io/controller-runtime/pkg/runtime/signals" | ||
) | ||
|
||
func main() { | ||
klog.InitFlags(nil) | ||
flag.Set("logtostderr", "true") | ||
flag.Parse() | ||
|
||
cfg := config.GetConfigOrDie() | ||
|
||
// Setup a Manager | ||
mgr, err := manager.New(cfg, manager.Options{}) | ||
if err != nil { | ||
klog.Fatalf("Failed to set up controller manager: %v", err) | ||
} | ||
|
||
cs, err := clientset.NewForConfig(cfg) | ||
if err != nil { | ||
klog.Fatalf("Failed to create client from configuration: %v", err) | ||
} | ||
|
||
recorder := mgr.GetRecorder("clusterapi-controller") | ||
|
||
// Initialize cluster actuator. | ||
clusterActuator, _ := cluster.NewClusterActuator(cs.ClusterV1alpha1(), recorder) | ||
|
||
// Initialize machine actuator. | ||
machineActuator, _ := machine.NewMachineActuator(cs.ClusterV1alpha1(), recorder) | ||
|
||
// Register cluster deployer | ||
common.RegisterClusterProvisioner("example", clusterActuator) | ||
|
||
if err := clusterapis.AddToScheme(mgr.GetScheme()); 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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Adds namespace to all resources. | ||
namespace: provider-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: provider- | ||
|
||
bases: | ||
- ./rbac/ | ||
- ./manager/ | ||
|
||
patchesStrategicMerge: | ||
- manager_image_patch.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Each entry in this list must resolve to an existing | ||
# resource definition in YAML. These are the resource | ||
# files that kustomize reads, modifies and emits as a | ||
# YAML string, with resources separated by document | ||
# markers ("---"). | ||
resources: | ||
- manager.yaml | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/example-provider-controller:latest | ||
name: manager |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Each entry in this list must resolve to an existing | ||
# resource definition in YAML. These are the resource | ||
# files that kustomize reads, modifies and emits as a | ||
# YAML string, with resources separated by document | ||
# markers ("---"). | ||
resources: | ||
- rbac_role_binding.yaml | ||
- rbac_role.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Each entry in this list must resolve to an existing | ||
# resource definition in YAML. These are the resource | ||
# files that kustomize reads, modifies and emits as a | ||
# YAML string, with resources separated by document | ||
# markers ("---"). | ||
resources: | ||
- cluster_v1alpha1_cluster.yaml | ||
- cluster_v1alpha1_machine.yaml | ||
- cluster_v1alpha1_machineclass.yaml | ||
- cluster_v1alpha1_machinedeployment.yaml | ||
- cluster_v1alpha1_machineset.yaml | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# 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: | ||
- ../crds/ | ||
- ../rbac/ | ||
- ../manager/ | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Each entry in this list must resolve to an existing | ||
# resource definition in YAML. These are the resource | ||
# files that kustomize reads, modifies and emits as a | ||
# YAML string, with resources separated by document | ||
# markers ("---"). | ||
resources: | ||
- manager.yaml | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Each entry in this list must resolve to an existing | ||
# resource definition in YAML. These are the resource | ||
# files that kustomize reads, modifies and emits as a | ||
# YAML string, with resources separated by document | ||
# markers ("---"). | ||
resources: | ||
- rbac_role_binding.yaml | ||
- rbac_role.yaml | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
|
||
go_library( | ||
name = "go_default_library", | ||
srcs = ["clusteractuator.go"], | ||
importpath = "sigs.k8s.io/cluster-api/pkg/provider/example/actuators/cluster", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//pkg/apis/cluster/v1alpha1:go_default_library", | ||
"//pkg/client/clientset_generated/clientset/typed/cluster/v1alpha1:go_default_library", | ||
"//vendor/k8s.io/api/core/v1:go_default_library", | ||
"//vendor/k8s.io/client-go/tools/record:go_default_library", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
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. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package cluster | ||
|
||
import ( | ||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/client-go/tools/record" | ||
clusterv1 "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1" | ||
clusterv1alpha1 "sigs.k8s.io/cluster-api/pkg/client/clientset_generated/clientset/typed/cluster/v1alpha1" | ||
) | ||
|
||
// Actuator is responsible for performing cluster reconciliation | ||
type Actuator struct { | ||
clusterV1alpha1 clusterv1alpha1.ClusterV1alpha1Interface | ||
recorder record.EventRecorder | ||
} | ||
|
||
// NewClusterActuator creates a new cluster actuator | ||
func NewClusterActuator(clusterV1alpha1 clusterv1alpha1.ClusterV1alpha1Interface, recorder record.EventRecorder) (*Actuator, error) { | ||
return &Actuator{ | ||
clusterV1alpha1: clusterV1alpha1, | ||
recorder: recorder, | ||
}, nil | ||
} | ||
|
||
// Reconcile will create or update the cluster | ||
func (a *Actuator) Reconcile(cluster *clusterv1.Cluster) error { | ||
a.recorder.Event(cluster, corev1.EventTypeWarning, "cluster-api", "clusteractuator Reconcile invoked") | ||
return nil | ||
} | ||
|
||
// Delete deletes a cluster and is invoked by the Cluster Controller | ||
func (a *Actuator) Delete(cluster *clusterv1.Cluster) error { | ||
a.recorder.Event(cluster, corev1.EventTypeWarning, "cluster-api", "clusteractuator Delete invoked") | ||
return nil | ||
} |
Oops, something went wrong.