-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
aws endpoint service principal lifecycle workflow was implemented
- Loading branch information
Showing
22 changed files
with
726 additions
and
1 deletion.
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
72 changes: 72 additions & 0 deletions
72
apis/clusterresources/v1beta1/awsendpointserviceprincipal_types.go
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,72 @@ | ||
/* | ||
Copyright 2022. | ||
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 v1beta1 | ||
|
||
import ( | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
// AWSEndpointServicePrincipalSpec defines the desired state of AWSEndpointServicePrincipal | ||
type AWSEndpointServicePrincipalSpec struct { | ||
// The ID of the cluster data center | ||
ClusterDataCenterID string `json:"clusterDataCenterId"` | ||
|
||
// The Instaclustr ID of the AWS endpoint service | ||
EndPointServiceID string `json:"endPointServiceId,omitempty"` | ||
|
||
// The IAM Principal ARN | ||
PrincipalARN string `json:"principalArn"` | ||
} | ||
|
||
// AWSEndpointServicePrincipalStatus defines the observed state of AWSEndpointServicePrincipal | ||
type AWSEndpointServicePrincipalStatus struct { | ||
// The Instaclustr ID of the IAM Principal ARN | ||
ID string `json:"id,omitempty"` | ||
|
||
// The Instaclustr ID of the AWS endpoint service | ||
EndPointServiceID string `json:"endPointServiceId,omitempty"` | ||
} | ||
|
||
//+kubebuilder:object:root=true | ||
//+kubebuilder:subresource:status | ||
|
||
// AWSEndpointServicePrincipal is the Schema for the awsendpointserviceprincipals API | ||
type AWSEndpointServicePrincipal struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
Spec AWSEndpointServicePrincipalSpec `json:"spec,omitempty"` | ||
Status AWSEndpointServicePrincipalStatus `json:"status,omitempty"` | ||
} | ||
|
||
func (r *AWSEndpointServicePrincipal) NewPatch() client.Patch { | ||
return client.MergeFrom(r.DeepCopy()) | ||
} | ||
|
||
//+kubebuilder:object:root=true | ||
|
||
// AWSEndpointServicePrincipalList contains a list of AWSEndpointServicePrincipal | ||
type AWSEndpointServicePrincipalList struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ListMeta `json:"metadata,omitempty"` | ||
Items []AWSEndpointServicePrincipal `json:"items"` | ||
} | ||
|
||
func init() { | ||
SchemeBuilder.Register(&AWSEndpointServicePrincipal{}, &AWSEndpointServicePrincipalList{}) | ||
} |
82 changes: 82 additions & 0 deletions
82
apis/clusterresources/v1beta1/awsendpointserviceprincipal_webhook.go
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,82 @@ | ||
/* | ||
Copyright 2022. | ||
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 v1beta1 | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
|
||
"k8s.io/apimachinery/pkg/runtime" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
logf "sigs.k8s.io/controller-runtime/pkg/log" | ||
"sigs.k8s.io/controller-runtime/pkg/webhook" | ||
) | ||
|
||
// log is for logging in this package. | ||
var awsendpointserviceprincipallog = logf.Log.WithName("awsendpointserviceprincipal-resource") | ||
|
||
func (r *AWSEndpointServicePrincipal) SetupWebhookWithManager(mgr ctrl.Manager) error { | ||
return ctrl.NewWebhookManagedBy(mgr). | ||
For(r). | ||
Complete() | ||
} | ||
|
||
//+kubebuilder:webhook:path=/validate-clusterresources-instaclustr-com-v1beta1-awsendpointserviceprincipal,mutating=false,failurePolicy=fail,sideEffects=None,groups=clusterresources.instaclustr.com,resources=awsendpointserviceprincipals,verbs=create;update,versions=v1beta1,name=vawsendpointserviceprincipal.kb.io,admissionReviewVersions=v1 | ||
|
||
var _ webhook.Validator = &AWSEndpointServicePrincipal{} | ||
|
||
var principalArnPattern, _ = regexp.Compile(`^arn:aws:iam::[0-9]{12}:(root$|user\/[\w+=,.@-]+|role\/[\w+=,.@-]+)$`) | ||
|
||
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type | ||
func (r *AWSEndpointServicePrincipal) ValidateCreate() error { | ||
awsendpointserviceprincipallog.Info("validate create", "name", r.Name) | ||
|
||
if r.Spec.ClusterDataCenterID == "" || | ||
r.Spec.PrincipalARN == "" { | ||
return fmt.Errorf("spec.clusterDataCenterId and spec.principalArn should be filled") | ||
} | ||
|
||
if !principalArnPattern.MatchString(r.Spec.PrincipalARN) { | ||
return fmt.Errorf("spec.principalArn doesn't match following pattern \"^arn:aws:iam::[0-9]{12}:(root$|user\\/[\\w+=,.@-]+|role\\/[\\w+=,.@-]+)$\"") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type | ||
func (r *AWSEndpointServicePrincipal) ValidateUpdate(old runtime.Object) error { | ||
awsendpointserviceprincipallog.Info("validate update", "name", r.Name) | ||
|
||
oldResource := old.(*AWSEndpointServicePrincipal) | ||
|
||
if r.Status.ID == "" { | ||
return r.ValidateCreate() | ||
} | ||
|
||
if r.Spec != oldResource.Spec { | ||
return fmt.Errorf("all fields in the spec are immutable") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type | ||
func (r *AWSEndpointServicePrincipal) ValidateDelete() error { | ||
awsendpointserviceprincipallog.Info("validate delete", "name", r.Name) | ||
|
||
return nil | ||
} |
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.
68 changes: 68 additions & 0 deletions
68
config/crd/bases/clusterresources.instaclustr.com_awsendpointserviceprincipals.yaml
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,68 @@ | ||
--- | ||
apiVersion: apiextensions.k8s.io/v1 | ||
kind: CustomResourceDefinition | ||
metadata: | ||
annotations: | ||
controller-gen.kubebuilder.io/version: v0.9.2 | ||
creationTimestamp: null | ||
name: awsendpointserviceprincipals.clusterresources.instaclustr.com | ||
spec: | ||
group: clusterresources.instaclustr.com | ||
names: | ||
kind: AWSEndpointServicePrincipal | ||
listKind: AWSEndpointServicePrincipalList | ||
plural: awsendpointserviceprincipals | ||
singular: awsendpointserviceprincipal | ||
scope: Namespaced | ||
versions: | ||
- name: v1beta1 | ||
schema: | ||
openAPIV3Schema: | ||
description: AWSEndpointServicePrincipal is the Schema for the awsendpointserviceprincipals | ||
API | ||
properties: | ||
apiVersion: | ||
description: 'APIVersion defines the versioned schema of this representation | ||
of an object. Servers should convert recognized schemas to the latest | ||
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' | ||
type: string | ||
kind: | ||
description: 'Kind is a string value representing the REST resource this | ||
object represents. Servers may infer this from the endpoint the client | ||
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' | ||
type: string | ||
metadata: | ||
type: object | ||
spec: | ||
description: AWSEndpointServicePrincipalSpec defines the desired state | ||
of AWSEndpointServicePrincipal | ||
properties: | ||
clusterDataCenterId: | ||
description: The ID of the cluster data center | ||
type: string | ||
endPointServiceId: | ||
description: The Instaclustr ID of the AWS endpoint service | ||
type: string | ||
principalArn: | ||
description: The IAM Principal ARN | ||
type: string | ||
required: | ||
- clusterDataCenterId | ||
- principalArn | ||
type: object | ||
status: | ||
description: AWSEndpointServicePrincipalStatus defines the observed state | ||
of AWSEndpointServicePrincipal | ||
properties: | ||
endPointServiceId: | ||
description: The Instaclustr ID of the AWS endpoint service | ||
type: string | ||
id: | ||
description: The Instaclustr ID of the IAM Principal ARN | ||
type: string | ||
type: object | ||
type: object | ||
served: true | ||
storage: true | ||
subresources: | ||
status: {} |
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
7 changes: 7 additions & 0 deletions
7
config/crd/patches/cainjection_in_clusterresources_awsendpointserviceprincipals.yaml
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,7 @@ | ||
# The following patch adds a directive for certmanager to inject CA into the CRD | ||
apiVersion: apiextensions.k8s.io/v1 | ||
kind: CustomResourceDefinition | ||
metadata: | ||
annotations: | ||
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME) | ||
name: awsendpointserviceprincipals.clusterresources.instaclustr.com |
16 changes: 16 additions & 0 deletions
16
config/crd/patches/webhook_in_clusterresources_awsendpointserviceprincipals.yaml
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,16 @@ | ||
# The following patch enables a conversion webhook for the CRD | ||
apiVersion: apiextensions.k8s.io/v1 | ||
kind: CustomResourceDefinition | ||
metadata: | ||
name: awsendpointserviceprincipals.clusterresources.instaclustr.com | ||
spec: | ||
conversion: | ||
strategy: Webhook | ||
webhook: | ||
clientConfig: | ||
service: | ||
namespace: system | ||
name: webhook-service | ||
path: /convert | ||
conversionReviewVersions: | ||
- v1 |
Oops, something went wrong.