Skip to content

Commit

Permalink
Test pass now 🎉
Browse files Browse the repository at this point in the history
Signed-off-by: Vince Prignano <[email protected]>
  • Loading branch information
vincepri committed Jun 24, 2019
1 parent 688f73d commit e30d9b8
Show file tree
Hide file tree
Showing 39 changed files with 592 additions and 439 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ config/ci/rbac/role_binding.yaml
config/ci/rbac/role.yaml
config/ci/manager/manager.yaml

config/crds-v1alpha1

10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,16 @@ generate-manifests: ## Generate manifests e.g. CRD, RBAC etc.
crd \
rbac:roleName=manager-role \
output:crd:dir=./config/crds
## Hack for MachineClass. This type has been deprecated in v1alpha2.
## Generating the types with the above command results in an error during tests,
## specifically `per-version schemas may not all be set to identical values (top-level validation should be used instead)`.
## This might be a bug in controller-tools that generates a multi-version CRD where only a single version is available.
go run vendor/sigs.k8s.io/controller-tools/cmd/controller-gen/main.go \
paths=./pkg/apis/cluster/v1alpha1 \
crd:trivialVersions=true \
output:crd:dir=./config/crds-v1alpha1
cp -f ./config/crds-v1alpha1/cluster.k8s.io_machineclasses.yaml ./config/crds/
## Copy files in CI folders.
cp -f ./config/rbac/role*.yaml ./config/ci/rbac/
cp -f ./config/manager/manager*.yaml ./config/ci/manager/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ var cfg *rest.Config

func TestMain(m *testing.M) {
t := &envtest.Environment{
CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crds")},
CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crds")},
KubeAPIServerFlags: append(envtest.DefaultKubeAPIServerFlags, "--feature-gates=CustomResourceWebhookConversion=true"),
}
apis.AddToScheme(scheme.Scheme)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ import (
"path"
"testing"

corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/pointer"
"sigs.k8s.io/cluster-api/pkg/apis/cluster/common"
"sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha2"
"sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha2/testutil"
Expand Down Expand Up @@ -56,6 +58,13 @@ func getMachineWithError(machineName, namespace string, nodeRef *v1.ObjectRefere
Name: machineName,
Namespace: namespace,
},
Spec: v1alpha2.MachineSpec{
InfrastructureRef: corev1.TypedLocalObjectReference{
APIGroup: pointer.StringPtr("infrastructure.clusters.k8s.io"),
Kind: "InfrastructureRef",
Name: "machine-infrastructure",
},
},
Status: newMachineStatus(nodeRef, errorReason, errorMessage),
}
}
Expand Down
1 change: 0 additions & 1 deletion cmd/example-provider/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ go_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",
Expand Down
6 changes: 1 addition & 5 deletions cmd/example-provider/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
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"
Expand Down Expand Up @@ -55,17 +54,14 @@ func main() {
// Initialize cluster actuator.
clusterActuator, _ := cluster.NewClusterActuator(cs.ClusterV1alpha2(), recorder)

// Initialize machine actuator.
machineActuator, _ := machine.NewMachineActuator(cs.ClusterV1alpha2(), recorder)

// Register cluster deployer
common.RegisterClusterProvisioner("example", clusterActuator)

if err := clusterapis.AddToScheme(mgr.GetScheme()); err != nil {
klog.Fatal(err)
}

capimachine.AddWithActuator(mgr, machineActuator)
capimachine.Add(mgr)
capicluster.AddWithActuator(mgr, clusterActuator)

if err := mgr.Start(signals.SetupSignalHandler()); err != nil {
Expand Down
4 changes: 0 additions & 4 deletions config/crds/cluster.k8s.io_clusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,6 @@ spec:
type: object
served: true
storage: false
subresources:
status: {}
- name: v1alpha2
schema:
openAPIV3Schema:
Expand Down Expand Up @@ -948,8 +946,6 @@ spec:
from this field, akin to component config.
type: object
type: object
required:
- clusterNetwork
type: object
status:
properties:
Expand Down
736 changes: 366 additions & 370 deletions config/crds/cluster.k8s.io_machineclasses.yaml

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion config/crds/cluster.k8s.io_machinedeployments.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,6 @@ spec:
labelSelectorPath: .status.labelSelector
specReplicasPath: .spec.replicas
statusReplicasPath: .status.replicas
status: {}
- name: v1alpha2
schema:
openAPIV3Schema:
Expand Down
18 changes: 1 addition & 17 deletions config/crds/cluster.k8s.io_machines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,7 @@ spec:
- ma
scope: Namespaced
versions:
- additionalPrinterColumns:
- JSONPath: .spec.providerID
description: Provider ID
name: ProviderID
type: string
- JSONPath: .status.phase
description: Machine status such as Terminating/Pending/Running/Failed etc
name: Phase
type: string
- JSONPath: .status.nodeRef.name
description: Node name associated with this machine
name: NodeName
priority: 1
type: string
name: v1alpha1
- name: v1alpha1
schema:
openAPIV3Schema:
description: / [Machine] Machine is the Schema for the machines API
Expand Down Expand Up @@ -852,8 +838,6 @@ spec:
type: object
served: true
storage: false
subresources:
status: {}
- additionalPrinterColumns:
- JSONPath: .spec.providerID
description: Provider ID
Expand Down
1 change: 0 additions & 1 deletion config/crds/cluster.k8s.io_machinesets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,6 @@ spec:
labelSelectorPath: .status.labelSelector
specReplicasPath: .spec.replicas
statusReplicasPath: .status.replicas
status: {}
- name: v1alpha2
schema:
openAPIV3Schema:
Expand Down
1 change: 0 additions & 1 deletion pkg/apis/cluster/v1alpha1/cluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const ClusterFinalizer = "cluster.cluster.k8s.io"
// Cluster is the Schema for the clusters API
// +k8s:openapi-gen=true
// +kubebuilder:resource:path=clusters,shortName=cl
// +kubebuilder:subresource:status
type Cluster struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down
4 changes: 0 additions & 4 deletions pkg/apis/cluster/v1alpha1/machine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ const (
// Machine is the Schema for the machines API
// +k8s:openapi-gen=true
// +kubebuilder:resource:path=machines,shortName=ma
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="ProviderID",type="string",JSONPath=".spec.providerID",description="Provider ID"
// +kubebuilder:printcolumn:name="Phase",type="string",JSONPath=".status.phase",description="Machine status such as Terminating/Pending/Running/Failed etc"
// +kubebuilder:printcolumn:name="NodeName",type="string",JSONPath=".status.nodeRef.name",description="Node name associated with this machine",priority=1
type Machine struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down
1 change: 0 additions & 1 deletion pkg/apis/cluster/v1alpha1/machinedeployment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ type MachineDeploymentStatus struct {
// MachineDeployment is the Schema for the machinedeployments API
// +k8s:openapi-gen=true
// +kubebuilder:resource:path=machinedeployments,shortName=md
// +kubebuilder:subresource:status
// +kubebuilder:subresource:scale:specpath=.spec.replicas,statuspath=.status.replicas,selectorpath=.status.labelSelector
type MachineDeployment struct {
metav1.TypeMeta `json:",inline"`
Expand Down
1 change: 0 additions & 1 deletion pkg/apis/cluster/v1alpha1/machineset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
// MachineSet ensures that a specified number of machines replicas are running at any given time.
// +k8s:openapi-gen=true
// +kubebuilder:resource:path=machinesets,shortName=ms
// +kubebuilder:subresource:status
// +kubebuilder:subresource:scale:specpath=.spec.replicas,statuspath=.status.replicas,selectorpath=.status.labelSelector
type MachineSet struct {
metav1.TypeMeta `json:",inline"`
Expand Down
3 changes: 2 additions & 1 deletion pkg/apis/cluster/v1alpha1/v1alpha1_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ var c client.Client

func TestMain(m *testing.M) {
t := &envtest.Environment{
CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "..", "config", "crds")},
CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "..", "config", "crds")},
KubeAPIServerFlags: append(envtest.DefaultKubeAPIServerFlags, "--feature-gates=CustomResourceWebhookConversion=true"),
}

err := SchemeBuilder.AddToScheme(scheme.Scheme)
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/cluster/v1alpha2/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go_library(
srcs = [
"cluster_types.go",
"common_type.go",
"defaults.go",
"doc.go",
"machine_types.go",
"machinedeployment_types.go",
Expand Down Expand Up @@ -41,10 +42,12 @@ go_test(
deps = [
"//vendor/github.com/onsi/gomega:go_default_library",
"//vendor/golang.org/x/net/context:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
"//vendor/k8s.io/client-go/kubernetes/scheme:go_default_library",
"//vendor/k8s.io/client-go/rest:go_default_library",
"//vendor/k8s.io/utils/pointer:go_default_library",
"//vendor/sigs.k8s.io/controller-runtime/pkg/client:go_default_library",
"//vendor/sigs.k8s.io/controller-runtime/pkg/envtest:go_default_library",
],
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/cluster/v1alpha2/cluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type Cluster struct {
type ClusterSpec struct {
// Cluster network configuration
// +optional
ClusterNetwork ClusterNetworkingConfig `json:"clusterNetwork"`
ClusterNetwork *ClusterNetworkingConfig `json:"clusterNetwork,omitempty"`

// Provider-specific serialized configuration to use during
// cluster creation. It is recommended that providers maintain
Expand Down
12 changes: 11 additions & 1 deletion pkg/apis/cluster/v1alpha2/machine_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ import (

"github.com/onsi/gomega"
"golang.org/x/net/context"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/pointer"
)

func TestStorageMachine(t *testing.T) {
Expand All @@ -34,7 +36,15 @@ func TestStorageMachine(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Namespace: "default",
}}
},
Spec: MachineSpec{
InfrastructureRef: corev1.TypedLocalObjectReference{
APIGroup: pointer.StringPtr("infrastructure.clusters.k8s.io"),
Kind: "InfrastructureRef",
Name: "machine-infrastructure",
},
},
}
g := gomega.NewGomegaWithT(t)

// Test Create
Expand Down
16 changes: 15 additions & 1 deletion pkg/apis/cluster/v1alpha2/machinedeployment_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ import (

"github.com/onsi/gomega"
"golang.org/x/net/context"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/pointer"
)

func TestStorageMachineDeployment(t *testing.T) {
Expand All @@ -34,7 +36,19 @@ func TestStorageMachineDeployment(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Namespace: "default",
}}
},
Spec: MachineDeploymentSpec{
Template: MachineTemplateSpec{
Spec: MachineSpec{
InfrastructureRef: corev1.TypedLocalObjectReference{
APIGroup: pointer.StringPtr("infrastructure.clusters.k8s.io"),
Kind: "InfrastructureRef",
Name: "machine-infrastructure",
},
},
},
},
}
g := gomega.NewGomegaWithT(t)

// Test Create
Expand Down
16 changes: 15 additions & 1 deletion pkg/apis/cluster/v1alpha2/machineset_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ import (

"github.com/onsi/gomega"
"golang.org/x/net/context"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/pointer"
)

func TestStorageMachineSet(t *testing.T) {
Expand All @@ -34,7 +36,19 @@ func TestStorageMachineSet(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Namespace: "default",
}}
},
Spec: MachineSetSpec{
Template: MachineTemplateSpec{
Spec: MachineSpec{
InfrastructureRef: corev1.TypedLocalObjectReference{
APIGroup: pointer.StringPtr("infrastructure.clusters.k8s.io"),
Kind: "InfrastructureRef",
Name: "machine-infrastructure",
},
},
},
},
}
g := gomega.NewGomegaWithT(t)

// Test Create
Expand Down
12 changes: 1 addition & 11 deletions pkg/apis/cluster/v1alpha2/testutil/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,6 @@ import "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha2"
// GetVanillaCluster return a bare minimum functional cluster resource object
func GetVanillaCluster() v1alpha2.Cluster {
return v1alpha2.Cluster{
Spec: v1alpha2.ClusterSpec{
ClusterNetwork: v1alpha2.ClusterNetworkingConfig{
Services: v1alpha2.NetworkRanges{
CIDRBlocks: []string{"10.96.0.0/12"},
},
Pods: v1alpha2.NetworkRanges{
CIDRBlocks: []string{"192.168.0.0/16"},
},
ServiceDomain: "cluster.local",
},
},
Spec: v1alpha2.ClusterSpec{},
}
}
3 changes: 2 additions & 1 deletion pkg/apis/cluster/v1alpha2/v1alpha2_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ var c client.Client

func TestMain(m *testing.M) {
t := &envtest.Environment{
CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "..", "config", "crds")},
CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "..", "config", "crds")},
KubeAPIServerFlags: append(envtest.DefaultKubeAPIServerFlags, "--feature-gates=CustomResourceWebhookConversion=true"),
}

err := SchemeBuilder.AddToScheme(scheme.Scheme)
Expand Down
6 changes: 5 additions & 1 deletion pkg/apis/cluster/v1alpha2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions pkg/controller/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ go_library(
srcs = [
"add_machinedeployment.go",
"add_machineset.go",
"add_node.go",
"add_noderef.go",
"controller.go",
],
Expand All @@ -14,7 +13,6 @@ go_library(
deps = [
"//pkg/controller/machinedeployment:go_default_library",
"//pkg/controller/machineset:go_default_library",
"//pkg/controller/node:go_default_library",
"//pkg/controller/noderef:go_default_library",
"//vendor/sigs.k8s.io/controller-runtime/pkg/manager:go_default_library",
],
Expand Down
3 changes: 2 additions & 1 deletion pkg/controller/cluster/cluster_reconciler_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ var cfg *rest.Config

func TestMain(m *testing.M) {
t := &envtest.Environment{
CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crds")},
CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crds")},
KubeAPIServerFlags: append(envtest.DefaultKubeAPIServerFlags, "--feature-gates=CustomResourceWebhookConversion=true"),
}
apis.AddToScheme(scheme.Scheme)

Expand Down
Loading

0 comments on commit e30d9b8

Please sign in to comment.