Skip to content

Commit 1508f31

Browse files
Implementation for cluster identity
1 parent 95aa2c6 commit 1508f31

39 files changed

+1536
-107
lines changed

Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,8 @@ generate-e2e-templates: $(KUSTOMIZE)
253253
$(KUSTOMIZE) build $(OCI_TEMPLATES)/v1beta1/cluster-template-externally-managed-vcn --load-restrictor LoadRestrictionsNone > $(OCI_TEMPLATES)/v1beta1/cluster-template-externally-managed-vcn.yaml
254254
$(KUSTOMIZE) build $(OCI_TEMPLATES)/v1beta1/cluster-template-machine-pool --load-restrictor LoadRestrictionsNone > $(OCI_TEMPLATES)/v1beta1/cluster-template-machine-pool.yaml
255255
$(KUSTOMIZE) build $(OCI_TEMPLATES)/v1beta1/cluster-template-managed --load-restrictor LoadRestrictionsNone > $(OCI_TEMPLATES)/v1beta1/cluster-template-managed.yaml
256+
$(KUSTOMIZE) build $(OCI_TEMPLATES)/v1beta1/cluster-template-managed-cluster-identity --load-restrictor LoadRestrictionsNone > $(OCI_TEMPLATES)/v1beta1/cluster-template-managed-cluster-identity.yaml
257+
$(KUSTOMIZE) build $(OCI_TEMPLATES)/v1beta1/cluster-template-cluster-identity --load-restrictor LoadRestrictionsNone > $(OCI_TEMPLATES)/v1beta1/cluster-template-cluster-identity.yaml
256258

257259
.PHONY: test-e2e-run
258260
test-e2e-run: generate-e2e-templates $(GINKGO) $(ENVSUBST) ## Run e2e tests

api/v1beta1/conditions_consts.go

+2
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,6 @@ const (
9999
ApiServerLoadBalancerEventReady = "APIServerLoadBalancerReady"
100100
// FailureDomainEventReady used after reconciliation has completed successfully
101101
FailureDomainEventReady = "FailureDomainsReady"
102+
// NamespaceNotAllowedByIdentity used to indicate cluster in a namespace not allowed by identity.
103+
NamespaceNotAllowedByIdentity = "NamespaceNotAllowedByIdentity"
102104
)

api/v1beta1/ocicluster_types.go

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package v1beta1
1818

1919
import (
20+
corev1 "k8s.io/api/core/v1"
2021
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2122
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
2223
)
@@ -39,6 +40,10 @@ type OCIClusterSpec struct {
3940
// +optional
4041
OCIResourceIdentifier string `json:"ociResourceIdentifier,omitempty"`
4142

43+
// IdentityRef is a reference to an identity(principal) to be used when reconciling this cluster
44+
// +optional
45+
IdentityRef *corev1.ObjectReference `json:"identityRef,omitempty"`
46+
4247
// NetworkSpec encapsulates all things related to OCI network.
4348
// +optional
4449
NetworkSpec NetworkSpec `json:"networkSpec,omitempty"`
+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
Copyright (c) 2022, 2023 Oracle and/or its affiliates.
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+
https://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 v1beta1
18+
19+
import (
20+
corev1 "k8s.io/api/core/v1"
21+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
23+
)
24+
25+
type PrincipalType string
26+
27+
const (
28+
// UserPrincipal represents a user principal.
29+
UserPrincipal PrincipalType = "UserPrincipal"
30+
)
31+
32+
// OCIClusterIdentitySpec defines the parameters that are used to create an OCIClusterIdentity.
33+
type OCIClusterIdentitySpec struct {
34+
// Type is the type of OCI Principal used.
35+
// UserPrincipal is the only supported value
36+
Type PrincipalType `json:"type"`
37+
38+
// PrincipalSecret is a secret reference which contains the authentication credentials for the principal.
39+
// +optional
40+
PrincipalSecret corev1.SecretReference `json:"principalSecret,omitempty"`
41+
42+
// AllowedNamespaces is used to identify the namespaces the clusters are allowed to use the identity from.
43+
// Namespaces can be selected either using an array of namespaces or with label selector.
44+
// An empty allowedNamespaces object indicates that OCIClusters can use this identity from any namespace.
45+
// If this object is nil, no namespaces will be allowed (default behaviour, if this field is not provided)
46+
// A namespace should be either in the NamespaceList or match with Selector to use the identity.
47+
//
48+
// +optional
49+
// +nullable
50+
AllowedNamespaces *AllowedNamespaces `json:"allowedNamespaces"`
51+
}
52+
53+
// AllowedNamespaces defines the namespaces the clusters are allowed to use the identity from
54+
type AllowedNamespaces struct {
55+
// A nil or empty list indicates that OCICluster cannot use the identity from any namespace.
56+
// NamespaceList takes precedence over the Selector.
57+
// +optional
58+
// +nullable
59+
NamespaceList []string `json:"list"`
60+
61+
// Selector is a selector of namespaces that OCICluster can
62+
// use this Identity from. This is a standard Kubernetes LabelSelector,
63+
// a label query over a set of resources. The result of matchLabels and
64+
// matchExpressions are ANDed.
65+
//
66+
// A nil or empty selector indicates that OCICluster cannot use this
67+
// OCIClusterIdentity from any namespace.
68+
// +optional
69+
Selector *metav1.LabelSelector `json:"selector"`
70+
}
71+
72+
// OCIClusterIdentityStatus defines the observed state of OCIClusterIdentity.
73+
type OCIClusterIdentityStatus struct {
74+
// Conditions defines current service state of the OCIClusterIdentity.
75+
// +optional
76+
Conditions clusterv1.Conditions `json:"conditions,omitempty"`
77+
}
78+
79+
//+kubebuilder:object:root=true
80+
//+kubebuilder:subresource:status
81+
82+
// OCIClusterIdentity is the Schema for the OCI Cluster Identity API
83+
type OCIClusterIdentity struct {
84+
metav1.TypeMeta `json:",inline"`
85+
metav1.ObjectMeta `json:"metadata,omitempty"`
86+
Spec OCIClusterIdentitySpec `json:"spec,omitempty"`
87+
Status OCIClusterIdentityStatus `json:"status,omitempty"`
88+
}
89+
90+
// +kubebuilder:object:root=true
91+
92+
// OCIClusterIdentityList contains a list of OCIClusterIdentity.
93+
type OCIClusterIdentityList struct {
94+
metav1.TypeMeta `json:",inline"`
95+
metav1.ListMeta `json:"metadata,omitempty"`
96+
Items []OCIClusterIdentity `json:"items"`
97+
}
98+
99+
func init() {
100+
SchemeBuilder.Register(&OCIClusterIdentity{}, &OCIClusterIdentityList{})
101+
}

api/v1beta1/zz_generated.deepcopy.go

+134
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cloud/scope/clients.go

+5
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ func (c *ClientProvider) GetOrBuildClient(region string) (OCIClients, error) {
100100
return regionalClient, nil
101101
}
102102

103+
// GetRegion returns the region from the authentication config provider
104+
func (c *ClientProvider) GetRegion() (string, error) {
105+
return c.ociAuthConfigProvider.Region()
106+
}
107+
103108
func createClients(region string, oCIAuthConfigProvider common.ConfigurationProvider, logger *logr.Logger) (OCIClients, error) {
104109
vcnClient, err := createVncClient(region, oCIAuthConfigProvider, logger)
105110
if err != nil {

cloud/scope/cluster_accessor.go

+9
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package scope
1818

1919
import (
2020
infrastructurev1beta1 "github.com/oracle/cluster-api-provider-oci/api/v1beta1"
21+
corev1 "k8s.io/api/core/v1"
2122
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
2223
)
2324

@@ -37,6 +38,10 @@ type OCIClusterAccessor interface {
3738
GetFreeformTags() map[string]string
3839
// GetName returns the name of the cluster.
3940
GetName() string
41+
// GetNameSpace returns the namespace of the cluster.
42+
GetNameSpace() string
43+
// GetRegion returns the region of the cluster, if specified in the spec.
44+
GetRegion() string
4045
// GetNetworkSpec returns the NetworkSpec of the cluster.
4146
GetNetworkSpec() *infrastructurev1beta1.NetworkSpec
4247
// SetControlPlaneEndpoint sets the control plane endpoint of the cluster.
@@ -47,4 +52,8 @@ type OCIClusterAccessor interface {
4752
SetFailureDomain(id string, spec clusterv1.FailureDomainSpec)
4853
// SetAvailabilityDomains sets the availability domain.
4954
SetAvailabilityDomains(ads map[string]infrastructurev1beta1.OCIAvailabilityDomain)
55+
// MarkConditionFalse marks the provided condition as false in the cluster object
56+
MarkConditionFalse(t clusterv1.ConditionType, reason string, severity clusterv1.ConditionSeverity, messageFormat string, messageArgs ...interface{})
57+
// GetIdentityRef returns the Identity reference of the cluster
58+
GetIdentityRef() *corev1.ObjectReference
5059
}

cloud/scope/oci_managed_cluster.go

+19
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,33 @@ package scope
1919
import (
2020
infrastructurev1beta1 "github.com/oracle/cluster-api-provider-oci/api/v1beta1"
2121
infrav1exp "github.com/oracle/cluster-api-provider-oci/exp/api/v1beta1"
22+
corev1 "k8s.io/api/core/v1"
2223
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
24+
"sigs.k8s.io/cluster-api/util/conditions"
2325
)
2426

2527
// OCIManagedCluster is the ClusterAccessor implementation for managed clusters(OKE)
2628
type OCIManagedCluster struct {
2729
OCIManagedCluster *infrav1exp.OCIManagedCluster
2830
}
2931

32+
func (c OCIManagedCluster) GetNameSpace() string {
33+
return c.OCIManagedCluster.Namespace
34+
}
35+
36+
func (c OCIManagedCluster) GetRegion() string {
37+
return c.OCIManagedCluster.Spec.Region
38+
}
39+
40+
func (c OCIManagedCluster) MarkConditionFalse(t clusterv1.ConditionType, reason string, severity clusterv1.ConditionSeverity, messageFormat string, messageArgs ...interface{}) {
41+
conditions.MarkFalse(c.OCIManagedCluster, infrastructurev1beta1.ClusterReadyCondition, reason, severity, messageFormat, messageArgs...)
42+
43+
}
44+
45+
func (c OCIManagedCluster) GetIdentityRef() *corev1.ObjectReference {
46+
return c.OCIManagedCluster.Spec.IdentityRef
47+
}
48+
3049
func (c OCIManagedCluster) GetOCIResourceIdentifier() string {
3150
return c.OCIManagedCluster.Spec.OCIResourceIdentifier
3251
}

0 commit comments

Comments
 (0)