Skip to content

Commit edf69b9

Browse files
authored
Merge pull request #1187 from gab-satchi/multi-tenancy-0.7
Multi tenancy support for v1alpha3
2 parents 645ce4a + 8263f73 commit edf69b9

23 files changed

+1660
-22
lines changed

api/v1alpha2/vspherecluster_conversion.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ func (src *VSphereCluster) ConvertTo(dstRaw conversion.Hub) error { // nolint
4848
if dst.Spec.CloudProviderConfiguration.ProviderConfig.Cloud != nil {
4949
dst.Spec.CloudProviderConfiguration.ProviderConfig.Cloud.ExtraArgs = restored.Spec.CloudProviderConfiguration.ProviderConfig.Cloud.ExtraArgs
5050
}
51-
51+
if restored.Spec.IdentityRef != nil {
52+
dst.Spec.IdentityRef = restored.Spec.IdentityRef
53+
}
5254
if restored.Spec.LoadBalancerRef != nil {
5355
dst.Spec.LoadBalancerRef = restored.Spec.LoadBalancerRef
5456
}

api/v1alpha3/condition_consts.go

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,6 @@ const (
4747
// while installing the container storage interface addon; those kind of errors are usually transient
4848
// the operation is automatically re-tried by the controller.
4949
CSIProvisioningFailedReason = "CSIProvisioningFailed"
50-
51-
// VCenterAvailableCondition documents the connectivity with vcenter
52-
// for a given VSphereCluster
53-
VCenterAvailableCondition clusterv1.ConditionType = "VCenterAvailable"
54-
55-
// VCenterUnreachableReason (Severity=Error) documents a VSphereCluster controller detecting
56-
// issues with VCenter reachability;
57-
VCenterUnreachableReason = "VCenterUnreachable"
5850
)
5951

6052
// Conditions and condition Reasons for the VSphereMachine and the VSphereVM object.
@@ -108,3 +100,24 @@ const (
108100
// NOTE: This reason does not apply to VSphereVM (this state happens after the VSphereVM is in ready state).
109101
WaitingForNetworkAddressesReason = "WaitingForNetworkAddresses"
110102
)
103+
104+
// Conditions and Reasons related to utilizing a VSphereIdentity to make connections to a VCenter. Can currently be used by VSphereCluster and VSphereVM
105+
106+
const (
107+
// VCenterAvailableCondition documents the connectivity with vcenter
108+
// for a given VSphereCluster
109+
VCenterAvailableCondition clusterv1.ConditionType = "VCenterAvailable"
110+
111+
// VCenterUnreachableReason (Severity=Error) documents a VSphereCluster controller detecting
112+
// issues with VCenter reachability;
113+
VCenterUnreachableReason = "VCenterUnreachable"
114+
115+
// CredentialsAvailableCondidtion is used by VSphereClusterIdentity when a credential secret is available and unused by other VSphereClusterIdentities
116+
CredentialsAvailableCondidtion clusterv1.ConditionType = "CredentialsAvailable"
117+
118+
// SecretNotAvailableReason is used when the secret referenced by the VSphereClusterIdentity cannot be found
119+
SecretNotAvailableReason = "SecretNotAvailable"
120+
121+
// SecretAlreadyInUseReason is used when another VSphereClusterIdentity is using the secret
122+
SecretAlreadyInUseReason = "SecretInUse"
123+
)

api/v1alpha3/vspherecluster_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ type VSphereClusterSpec struct {
6262
// DEPRECATED: will be removed in v1alpha4
6363
// +optional
6464
LoadBalancerRef *corev1.ObjectReference `json:"loadBalancerRef,omitempty"`
65+
66+
// IdentityRef is a reference to either a Secret or VSphereClusterIdentity that contains
67+
// the identity to use when reconciling the cluster.
68+
// +optional
69+
IdentityRef *VSphereIdentityReference `json:"identityRef,omitempty"`
6570
}
6671

6772
// VSphereClusterStatus defines the observed state of VSphereClusterSpec
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
Copyright 2021 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha3
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha3"
22+
)
23+
24+
const (
25+
SecretIdentitySetFinalizer = "identity/infrastructure.cluster.x-k8s.io"
26+
)
27+
28+
type VSphereClusterIdentitySpec struct {
29+
// SecretName references a Secret inside the controller namespace with the credentials to use
30+
// +kubebuilder:validation:MinLength=1
31+
SecretName string `json:"secretName,omitempty"`
32+
33+
// AllowedNamespaces is used to identify which namespaces are allowed to use this account.
34+
// Namespaces can be selected with a label selector.
35+
// If this object is nil, no namespaces will be allowed
36+
// +optional
37+
AllowedNamespaces *AllowedNamespaces `json:"allowedNamespaces,omitempty"`
38+
}
39+
40+
type VSphereClusterIdentityStatus struct {
41+
// +optional
42+
Ready bool `json:"ready,omitempty"`
43+
44+
// Conditions defines current service state of the VSphereCluster.
45+
// +optional
46+
Conditions clusterv1.Conditions `json:"conditions,omitempty"`
47+
}
48+
49+
type AllowedNamespaces struct {
50+
// Selector is a standard Kubernetes LabelSelector. A label query over a set of resources.
51+
// +optional
52+
Selector metav1.LabelSelector `json:"selector"`
53+
}
54+
55+
type VSphereIdentityKind string
56+
57+
var (
58+
VSphereClusterIdentityKind = VSphereIdentityKind("VSphereClusterIdentity")
59+
SecretKind = VSphereIdentityKind("Secret")
60+
)
61+
62+
type VSphereIdentityReference struct {
63+
// Kind of the identity. Can either be VSphereClusterIdentity or Secret
64+
// +kubebuilder:validation:Enum=VSphereClusterIdentity;Secret
65+
Kind VSphereIdentityKind `json:"kind"`
66+
67+
// Name of the identity.
68+
// +kubebuilder:validation:MinLength=1
69+
Name string `json:"name"`
70+
}
71+
72+
func (c *VSphereClusterIdentity) GetConditions() clusterv1.Conditions {
73+
return c.Status.Conditions
74+
}
75+
76+
func (c *VSphereClusterIdentity) SetConditions(conditions clusterv1.Conditions) {
77+
c.Status.Conditions = conditions
78+
}
79+
80+
// +kubebuilder:object:root=true
81+
// +kubebuilder:resource:path=vsphereclusteridentities,scope=Cluster,categories=cluster-api
82+
// +kubebuilder:storageversion
83+
// +kubebuilder:subresource:status
84+
85+
// VSphereClusterIdentity defines the account to be used for reconciling clusters
86+
type VSphereClusterIdentity struct {
87+
metav1.TypeMeta `json:",inline"`
88+
metav1.ObjectMeta `json:"metadata,omitempty"`
89+
90+
Spec VSphereClusterIdentitySpec `json:"spec,omitempty"`
91+
Status VSphereClusterIdentityStatus `json:"status,omitempty"`
92+
}
93+
94+
// +kubebuilder:object:root=true
95+
// VSphereClusterIdentityList contains a list of VSphereClusterIdentity
96+
type VSphereClusterIdentityList struct {
97+
metav1.TypeMeta `json:",inline"`
98+
metav1.ListMeta `json:"metadata,omitempty"`
99+
Items []VSphereClusterIdentity `json:"items"`
100+
}
101+
102+
func init() {
103+
SchemeBuilder.Register(&VSphereClusterIdentity{}, &VSphereClusterIdentityList{})
104+
}

api/v1alpha3/zz_generated.deepcopy.go

Lines changed: 137 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)