Skip to content

Commit

Permalink
Merge pull request #1198 from asalkeld/implement-externally-managed-a…
Browse files Browse the repository at this point in the history
…nnotation

Implement externally managed annotation (also update cluster-api to v0.4.0)
  • Loading branch information
k8s-ci-robot authored Jun 30, 2021
2 parents 2e26826 + e5f3459 commit 56db563
Show file tree
Hide file tree
Showing 8 changed files with 704 additions and 300 deletions.
24 changes: 22 additions & 2 deletions controllers/vspherecluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (
"sigs.k8s.io/cluster-api/util/annotations"
"sigs.k8s.io/cluster-api/util/conditions"
"sigs.k8s.io/cluster-api/util/patch"
"sigs.k8s.io/cluster-api/util/predicates"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
Expand Down Expand Up @@ -86,15 +87,33 @@ func AddClusterControllerToManager(ctx *context.ControllerManagerContext, mgr ma
}

reconciler := clusterReconciler{ControllerContext: controllerContext}

clusterToInfraFn := clusterutilv1.ClusterToInfrastructureMapFunc(clusterControlledTypeGVK)
return ctrl.NewControllerManagedBy(mgr).
// Watch the controlled, infrastructure resource.
For(clusterControlledType).
// Watch the CAPI resource that owns this infrastructure resource.
Watches(
&source.Kind{Type: &clusterv1.Cluster{}},
handler.EnqueueRequestsFromMapFunc(clusterutilv1.ClusterToInfrastructureMapFunc(clusterControlledTypeGVK)),
handler.EnqueueRequestsFromMapFunc(func(o client.Object) []reconcile.Request {
requests := clusterToInfraFn(o)
if requests == nil {
return nil
}

c := &infrav1.VSphereCluster{}
if err := reconciler.Client.Get(ctx, requests[0].NamespacedName, c); err != nil {
reconciler.Logger.V(4).Error(err, "Failed to get VSphereCluster")
return nil
}

if annotations.IsExternallyManaged(c) {
reconciler.Logger.V(4).Info("VSphereCluster is externally managed, skipping mapping.")
return nil
}
return requests
}),
).

// Watch the infrastructure machine resources that belong to the control
// plane. This controller needs to reconcile the infrastructure cluster
// once a control plane machine has an IP address.
Expand All @@ -121,6 +140,7 @@ func AddClusterControllerToManager(ctx *context.ControllerManagerContext, mgr ma
&source.Channel{Source: ctx.GetGenericEventChannelFor(clusterControlledTypeGVK)},
&handler.EnqueueRequestForObject{},
).
WithEventFilter(predicates.ResourceIsNotExternallyManaged(reconciler.Logger)).
WithOptions(controller.Options{MaxConcurrentReconciles: ctx.MaxConcurrentReconciles}).
Complete(reconciler)
}
Expand Down
38 changes: 23 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,32 @@ go 1.16
require (
github.com/antihax/optional v1.0.0
github.com/go-logr/logr v0.4.0
github.com/google/go-cmp v0.5.5
github.com/google/uuid v1.1.2
github.com/onsi/ginkgo v1.15.2
github.com/onsi/gomega v1.11.0
github.com/google/go-cmp v0.5.6
github.com/google/uuid v1.2.0
github.com/onsi/ginkgo v1.16.4
github.com/onsi/gomega v1.13.0
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v1.1.3
github.com/vmware/govmomi v0.23.1
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2
golang.org/x/oauth2 v0.0.0-20210615190721-d04028783cf1
gopkg.in/gcfg.v1 v1.2.3
k8s.io/api v0.21.0-beta.1
k8s.io/apiextensions-apiserver v0.21.0-beta.1
k8s.io/apimachinery v0.21.0-beta.1
k8s.io/client-go v0.21.0-beta.1
k8s.io/klog/v2 v2.8.0
k8s.io/utils v0.0.0-20210305010621-2afb4311ab10
sigs.k8s.io/cluster-api v0.3.11-0.20210324181938-d2a9e7c9fb2e
sigs.k8s.io/controller-runtime v0.9.0-alpha.1
sigs.k8s.io/kind v0.9.0
gopkg.in/warnings.v0 v0.1.2 // indirect
k8s.io/api v0.21.2
k8s.io/apiextensions-apiserver v0.21.2
k8s.io/apimachinery v0.21.2
k8s.io/client-go v0.21.2
k8s.io/klog/v2 v2.9.0
k8s.io/utils v0.0.0-20210527160623-6fdb442a123b
sigs.k8s.io/cluster-api v0.4.0
sigs.k8s.io/cluster-api/test v0.4.0
sigs.k8s.io/controller-runtime v0.9.1
sigs.k8s.io/kind v0.11.1
sigs.k8s.io/yaml v1.2.0
)

replace (
github.com/onsi/ginkgo => github.com/onsi/ginkgo v1.16.1
github.com/onsi/gomega => github.com/onsi/gomega v1.11.0
sigs.k8s.io/cluster-api => sigs.k8s.io/cluster-api v0.4.0
)
885 changes: 626 additions & 259 deletions go.sum

Large diffs are not rendered by default.

29 changes: 15 additions & 14 deletions packaging/flavorgen/flavors/generators.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"sigs.k8s.io/cluster-api-provider-vsphere/pkg/identity"
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha4"
bootstrapv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1alpha4"
kubeadmv1beta1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/types/v1beta1"
controlplanev1 "sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1alpha4"
addonsv1alpha4 "sigs.k8s.io/cluster-api/exp/addons/api/v1alpha4"
"sigs.k8s.io/yaml"
Expand Down Expand Up @@ -157,14 +156,14 @@ func defaultVirtualMachineCloneSpec() infrav1.VirtualMachineCloneSpec {

func defaultKubeadmInitSpec(files []bootstrapv1.File) bootstrapv1.KubeadmConfigSpec {
return bootstrapv1.KubeadmConfigSpec{
InitConfiguration: &kubeadmv1beta1.InitConfiguration{
InitConfiguration: &bootstrapv1.InitConfiguration{
NodeRegistration: defaultNodeRegistrationOptions(),
},
JoinConfiguration: &kubeadmv1beta1.JoinConfiguration{
JoinConfiguration: &bootstrapv1.JoinConfiguration{
NodeRegistration: defaultNodeRegistrationOptions(),
},
ClusterConfiguration: &kubeadmv1beta1.ClusterConfiguration{
APIServer: kubeadmv1beta1.APIServer{
ClusterConfiguration: &bootstrapv1.ClusterConfiguration{
APIServer: bootstrapv1.APIServer{
ControlPlaneComponent: defaultControlPlaneComponent(),
},
ControllerManager: defaultControlPlaneComponent(),
Expand All @@ -189,7 +188,7 @@ func newKubeadmConfigTemplate() bootstrapv1.KubeadmConfigTemplate {
Spec: bootstrapv1.KubeadmConfigTemplateSpec{
Template: bootstrapv1.KubeadmConfigTemplateResource{
Spec: bootstrapv1.KubeadmConfigSpec{
JoinConfiguration: &kubeadmv1beta1.JoinConfiguration{
JoinConfiguration: &bootstrapv1.JoinConfiguration{
NodeRegistration: defaultNodeRegistrationOptions(),
},
Users: defaultUsers(),
Expand All @@ -200,8 +199,8 @@ func newKubeadmConfigTemplate() bootstrapv1.KubeadmConfigTemplate {
}
}

func defaultNodeRegistrationOptions() kubeadmv1beta1.NodeRegistrationOptions {
return kubeadmv1beta1.NodeRegistrationOptions{
func defaultNodeRegistrationOptions() bootstrapv1.NodeRegistrationOptions {
return bootstrapv1.NodeRegistrationOptions{
Name: "{{ ds.meta_data.hostname }}",
CRISocket: "/var/run/containerd/containerd.sock",
KubeletExtraArgs: defaultExtraArgs(),
Expand All @@ -220,8 +219,8 @@ func defaultUsers() []bootstrapv1.User {
}
}

func defaultControlPlaneComponent() kubeadmv1beta1.ControlPlaneComponent {
return kubeadmv1beta1.ControlPlaneComponent{
func defaultControlPlaneComponent() bootstrapv1.ControlPlaneComponent {
return bootstrapv1.ControlPlaneComponent{
ExtraArgs: defaultExtraArgs(),
}
}
Expand Down Expand Up @@ -458,10 +457,12 @@ func newKubeadmControlplane(replicas int, infraTemplate infrav1.VSphereMachineTe
Spec: controlplanev1.KubeadmControlPlaneSpec{
Replicas: pointer.Int32Ptr(int32(replicas)),
Version: env.KubernetesVersionVar,
InfrastructureTemplate: corev1.ObjectReference{
APIVersion: infraTemplate.GroupVersionKind().GroupVersion().String(),
Kind: infraTemplate.Kind,
Name: infraTemplate.Name,
MachineTemplate: controlplanev1.KubeadmControlPlaneMachineTemplate{
InfrastructureRef: corev1.ObjectReference{
APIVersion: infraTemplate.GroupVersionKind().GroupVersion().String(),
Kind: infraTemplate.Kind,
Name: infraTemplate.Name,
},
},
KubeadmConfigSpec: defaultKubeadmInitSpec(files),
},
Expand Down
9 changes: 5 additions & 4 deletions templates/cluster-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,11 @@ metadata:
name: '${CLUSTER_NAME}'
namespace: '${NAMESPACE}'
spec:
infrastructureTemplate:
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha4
kind: VSphereMachineTemplate
name: '${CLUSTER_NAME}'
machineTemplate:
infrastructureRef:
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha4
kind: VSphereMachineTemplate
name: '${CLUSTER_NAME}'
kubeadmConfigSpec:
clusterConfiguration:
apiServer:
Expand Down
7 changes: 4 additions & 3 deletions test/e2e/config/vsphere-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ providers:
versions:
- name: v0.4.0
# Use manifest from source files
value: "https://storage.googleapis.com/artifacts.k8s-staging-cluster-api.appspot.com/components/nightly_master_20210325/core-components.yaml"
value: "https://github.com/kubernetes-sigs/cluster-api/releases/download/v0.4.0/core-components.yaml"
type: "url"
files:
- sourcePath: "../data/shared/metadata.yaml"
Expand All @@ -45,7 +45,7 @@ providers:
versions:
- name: v0.4.0
# Use manifest from source files
value: "https://storage.googleapis.com/artifacts.k8s-staging-cluster-api.appspot.com/components/nightly_master_20210325/bootstrap-components.yaml"
value: "https://github.com/kubernetes-sigs/cluster-api/releases/download/v0.4.0/bootstrap-components.yaml"
type: "url"
files:
- sourcePath: "../data/shared/metadata.yaml"
Expand All @@ -60,7 +60,7 @@ providers:
versions:
- name: v0.4.0
# Use manifest from source files
value: "https://storage.googleapis.com/artifacts.k8s-staging-cluster-api.appspot.com/components/nightly_master_20210325/control-plane-components.yaml"
value: "https://github.com/kubernetes-sigs/cluster-api/releases/download/v0.4.0/control-plane-components.yaml"
type: "url"
files:
- sourcePath: "../data/shared/metadata.yaml"
Expand Down Expand Up @@ -93,6 +93,7 @@ variables:
EXP_CLUSTER_RESOURCE_SET: "true"
CONTROL_PLANE_MACHINE_COUNT: 1
WORKER_MACHINE_COUNT: 1
IP_FAMILY: "IPv4"
VSPHERE_TLS_THUMBPRINT: "4F:AF:22:BD:C8:B2:AC:DE:0A:04:71:02:D1:62:05:50:2B:A2:54:E9"
VSPHERE_DATACENTER: "SDDC-Datacenter"
VSPHERE_FOLDER: "clusterapi"
Expand Down
7 changes: 4 additions & 3 deletions test/e2e/config/vsphere-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ providers:
versions:
- name: v0.4.0
# Use manifest from source files
value: "https://storage.googleapis.com/artifacts.k8s-staging-cluster-api.appspot.com/components/nightly_master_20210325/core-components.yaml"
value: "https://github.com/kubernetes-sigs/cluster-api/releases/download/v0.4.0/core-components.yaml"
type: "url"
files:
- sourcePath: "../data/shared/metadata.yaml"
Expand All @@ -48,7 +48,7 @@ providers:
versions:
- name: v0.4.0
# Use manifest from source files
value: "https://storage.googleapis.com/artifacts.k8s-staging-cluster-api.appspot.com/components/nightly_master_20210325/bootstrap-components.yaml"
value: "https://github.com/kubernetes-sigs/cluster-api/releases/download/v0.4.0/bootstrap-components.yaml"
type: "url"
files:
- sourcePath: "../data/shared/metadata.yaml"
Expand All @@ -63,7 +63,7 @@ providers:
versions:
- name: v0.4.0
# Use manifest from source files
value: "https://storage.googleapis.com/artifacts.k8s-staging-cluster-api.appspot.com/components/nightly_master_20210325/control-plane-components.yaml"
value: "https://github.com/kubernetes-sigs/cluster-api/releases/download/v0.4.0/control-plane-components.yaml"
type: "url"
files:
- sourcePath: "../data/shared/metadata.yaml"
Expand Down Expand Up @@ -97,6 +97,7 @@ variables:
EXP_CLUSTER_RESOURCE_SET: "true"
CONTROL_PLANE_MACHINE_COUNT: 1
WORKER_MACHINE_COUNT: 1
IP_FAMILY: "IPv4"
# Following CAPV variables should be set before testing
VSPHERE_SERVER: "vcenter.vmware.com"
VSPHERE_DATACENTER: "SDDC-Datacenter"
Expand Down
5 changes: 5 additions & 0 deletions test/e2e/log_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (

"github.com/pkg/errors"
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha4"
expv1 "sigs.k8s.io/cluster-api/exp/api/v1alpha4"
"sigs.k8s.io/controller-runtime/pkg/client"
kinderrors "sigs.k8s.io/kind/pkg/errors"
)
Expand All @@ -41,6 +42,10 @@ const (

type LogCollector struct{}

func (collector LogCollector) CollectMachinePoolLog(ctx context.Context, managementClusterClient client.Client, m *expv1.MachinePool, outputPath string) error {
return nil
}

func (collector LogCollector) CollectMachineLog(_ context.Context, _ client.Client, m *clusterv1.Machine, outputPath string) error {
var hostIPAddr string
for _, address := range m.Status.Addresses {
Expand Down

0 comments on commit 56db563

Please sign in to comment.