-
Notifications
You must be signed in to change notification settings - Fork 431
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
switch to using getting identity values from internal type
add values to azurecluster instead of expecting an azureidentity
- Loading branch information
1 parent
ea0133f
commit 516cbd2
Showing
28 changed files
with
711 additions
and
104 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,105 @@ | ||
/* | ||
Copyright 2020 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 v1alpha3 | ||
|
||
import ( | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha3" | ||
) | ||
|
||
// AzureClusterIdentitySpec defines the parameters that are used to create an AzureIdentity | ||
type AzureClusterIdentitySpec struct { | ||
// UserAssignedMSI or Service Principal | ||
Type IdentityType `json:"type"` | ||
// User assigned MSI resource id. | ||
// +optional | ||
ResourceID string `json:"resourceID,omitempty"` | ||
// Both User Assigned MSI and SP can use this field. | ||
ClientID string `json:"clientID"` | ||
// ClientSecret is a secret reference which should contain either a Service Principal password or certificate secret. | ||
// +optional | ||
ClientSecret corev1.SecretReference `json:"clientSecret,omitempty"` | ||
// Service principal primary tenant id. | ||
TenantID string `json:"tenantID"` | ||
// AllowedNamespaces is an array of namespaces that AzureClusters can | ||
// use this Identity from. | ||
// | ||
// An empty list (default) indicates that AzureClusters can use this | ||
// Identity from any namespace. This field is intentionally not a | ||
// pointer because the nil behavior (no namespaces) is undesirable here. | ||
// +optional | ||
AllowedNamespaces []string `json:"allowedNamespaces"` | ||
} | ||
|
||
// AzureClusterIdentityStatus defines the observed state of AzureClusterIdentity | ||
type AzureClusterIdentityStatus struct { | ||
// Conditions defines current service state of the AzureClusterIdentity. | ||
// +optional | ||
Conditions clusterv1.Conditions `json:"conditions,omitempty"` | ||
} | ||
|
||
// +kubebuilder:object:root=true | ||
// +kubebuilder:resource:path=azureclusteridentities,scope=Namespaced,categories=cluster-api | ||
// +kubebuilder:storageversion | ||
// +kubebuilder:subresource:status | ||
|
||
// AzureClusterIdentity is the Schema for the azureclustersidentities API | ||
type AzureClusterIdentity struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
Spec AzureClusterIdentitySpec `json:"spec,omitempty"` | ||
Status AzureClusterIdentityStatus `json:"status,omitempty"` | ||
} | ||
|
||
// +kubebuilder:object:root=true | ||
|
||
// AzureClusterIdentityList contains a list of AzureClusterIdentity | ||
type AzureClusterIdentityList struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ListMeta `json:"metadata,omitempty"` | ||
Items []AzureClusterIdentity `json:"items"` | ||
} | ||
|
||
// GetConditions returns the list of conditions for an AzureClusterIdentity API object. | ||
func (c *AzureClusterIdentity) GetConditions() clusterv1.Conditions { | ||
return c.Status.Conditions | ||
} | ||
|
||
// SetConditions will set the given conditions on an AzureClusterIdentity object | ||
func (c *AzureClusterIdentity) SetConditions(conditions clusterv1.Conditions) { | ||
c.Status.Conditions = conditions | ||
} | ||
|
||
// ClusterNamespaceAllowed indicates if the cluster namespace is allowed | ||
func (c *AzureClusterIdentity) ClusterNamespaceAllowed(namespace string) bool { | ||
if len(c.Spec.AllowedNamespaces) == 0 { | ||
return true | ||
} | ||
for _, v := range c.Spec.AllowedNamespaces { | ||
if v == namespace { | ||
return true | ||
} | ||
} | ||
|
||
return false | ||
} | ||
|
||
func init() { | ||
SchemeBuilder.Register(&AzureClusterIdentity{}, &AzureClusterIdentityList{}) | ||
} |
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,71 @@ | ||
/* | ||
Copyright 2020 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 v1alpha3 | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestAllowedNamespaces(t *testing.T) { | ||
g := NewWithT(t) | ||
|
||
tests := []struct { | ||
name string | ||
identity *AzureClusterIdentity | ||
clusterNamespace string | ||
expected bool | ||
}{ | ||
{ | ||
name: "allow any cluster namespace when empty", | ||
identity: &AzureClusterIdentity{ | ||
Spec: AzureClusterIdentitySpec{ | ||
AllowedNamespaces: []string{}, | ||
}, | ||
}, | ||
clusterNamespace: "default", | ||
expected: true, | ||
}, | ||
{ | ||
name: "allow cluster with namespace in list", | ||
identity: &AzureClusterIdentity{ | ||
Spec: AzureClusterIdentitySpec{ | ||
AllowedNamespaces: []string{"namespace24", "namespace32"}, | ||
}, | ||
}, | ||
clusterNamespace: "namespace24", | ||
expected: true, | ||
}, | ||
{ | ||
name: "don't allow cluster with namespace not in list", | ||
identity: &AzureClusterIdentity{ | ||
Spec: AzureClusterIdentitySpec{ | ||
AllowedNamespaces: []string{"namespace24", "namespace32"}, | ||
}, | ||
}, | ||
clusterNamespace: "namespace8", | ||
expected: false, | ||
}, | ||
} | ||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
actual := tc.identity.ClusterNamespaceAllowed(tc.clusterNamespace) | ||
g.Expect(actual).To(Equal(tc.expected)) | ||
}) | ||
} | ||
} |
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
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
Oops, something went wrong.