-
Notifications
You must be signed in to change notification settings - Fork 187
Create adoption reconciler #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| // Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"). You may | ||
| // not use this file except in compliance with the License. A copy of the | ||
| // License is located at | ||
| // | ||
| // http://aws.amazon.com/apache2.0/ | ||
| // | ||
| // or in the "license" file accompanying this file. This file 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 v1alpha1 | ||
|
|
||
| import ( | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| ) | ||
|
|
||
| // AdoptedResourceSpec defines the desired state of the AdoptedResource. | ||
| type AdoptedResourceSpec struct { | ||
| // +kubebuilder:validation:Required | ||
| Kubernetes *TargetKubernetesResource `json:"kubernetes"` | ||
| // +kubebuilder:validation:Required | ||
| AWS *AWSIdentifiers `json:"aws"` | ||
| } | ||
|
|
||
| // AdoptedResourceStatus defines the observed status of the AdoptedResource. | ||
| type AdoptedResourceStatus struct { | ||
| // A collection of `ackv1alpha1.Condition` objects that describe the various | ||
| // terminal states of the adopted resource CR and its target custom resource | ||
| Conditions []*Condition `json:"conditions"` | ||
| } | ||
|
|
||
| // AdoptedResource is the schema for the AdoptedResource API. | ||
| // +kubebuilder:object:root=true | ||
| // +kubebuilder:subresource:status | ||
| type AdoptedResource struct { | ||
| metav1.TypeMeta `json:",inline"` | ||
| metav1.ObjectMeta `json:"metadata,omitempty"` | ||
| Spec AdoptedResourceSpec `json:"spec,omitempty"` | ||
| Status AdoptedResourceStatus `json:"status,omitempty"` | ||
| } | ||
|
|
||
| // AdoptedResourceList defines a list of AdoptedResources. | ||
| // +kubebuilder:object:root=true | ||
| // +kubebuilder:printcolumn:name="AdoptionStatus",type=string,JSONPath=`.status.adoptionStatus` | ||
| type AdoptedResourceList struct { | ||
| metav1.TypeMeta `json:",inline"` | ||
| metav1.ListMeta `json:"metadata,omitempty"` | ||
| Items []AdoptedResource `json:"items"` | ||
| } | ||
|
|
||
| func init() { | ||
| SchemeBuilder.Register(&AdoptedResource{}, &AdoptedResourceList{}) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,9 @@ import ( | |
| type ConditionType string | ||
|
|
||
| const ( | ||
| // ConditionTypeAdopted indicates that the adopted resource custom resource | ||
| // has been successfully reconciled and the target has been created | ||
| ConditionTypeAdopted ConditionType = "ACK.Adopted" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this condition to be applied to the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This condition is currently being applied to the |
||
| // ConditionTypeResourceSynced indicates the state of the resource in the | ||
| // backend service is in sync with the ACK service controller | ||
| ConditionTypeResourceSynced ConditionType = "ACK.ResourceSynced" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| // Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"). You may | ||
| // not use this file except in compliance with the License. A copy of the | ||
| // License is located at | ||
| // | ||
| // http://aws.amazon.com/apache2.0/ | ||
| // | ||
| // or in the "license" file accompanying this file. This file 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 v1alpha1 | ||
|
|
||
| import ( | ||
| "k8s.io/apimachinery/pkg/runtime/schema" | ||
| "sigs.k8s.io/controller-runtime/pkg/scheme" | ||
| ) | ||
|
|
||
| var ( | ||
| // GroupVersion is the API Group Version used to register the objects | ||
| GroupVersion = schema.GroupVersion{Group: "services.k8s.aws", Version: "v1alpha1"} | ||
|
|
||
| // SchemeBuilder is used to add go types to the GroupVersionKind scheme | ||
| SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} | ||
|
|
||
| // AddToScheme adds the types in this group-version to the given scheme. | ||
| AddToScheme = SchemeBuilder.AddToScheme | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| // Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"). You may | ||
| // not use this file except in compliance with the License. A copy of the | ||
| // License is located at | ||
| // | ||
| // http://aws.amazon.com/apache2.0/ | ||
| // | ||
| // or in the "license" file accompanying this file. This file 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 v1alpha1 | ||
|
|
||
| // AWSIdentifiers provide all unique ways to reference an AWS resource. | ||
| type AWSIdentifiers struct { | ||
| // ARN is the AWS Resource Name for the resource. It is a globally | ||
| // unique identifier. | ||
| ARN *AWSResourceName `json:"arn,omitempty"` | ||
| // NameOrId is a user-supplied string identifier for the resource. It may | ||
| // or may not be globally unique, depending on the type of resource. | ||
| NameOrID *string `json:"nameOrID,omitempty"` | ||
| } | ||
|
|
||
| // TargetKubernetesResource provides all the values necessary to identify a given ACK type | ||
| // and override any metadata values when creating a resource of that type. | ||
| type TargetKubernetesResource struct { | ||
| // +kubebuilder:validation:Required | ||
| Group *string `json:"group"` | ||
| // +kubebuilder:validation:Required | ||
| Kind *string `json:"kind"` | ||
| Metadata *PartialObjectMeta `json:"metadata,omitempty"` | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| // Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"). You may | ||
| // not use this file except in compliance with the License. A copy of the | ||
| // License is located at | ||
| // | ||
| // http://aws.amazon.com/apache2.0/ | ||
| // | ||
| // or in the "license" file accompanying this file. This file 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 v1alpha1 | ||
|
|
||
| import ( | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| ) | ||
|
|
||
| // ObjectMeta is metadata that all persisted resources must have, which includes all objects | ||
| // users must create. | ||
| // It is not possible to use `metav1.ObjectMeta` inside spec, as the controller-gen | ||
| // automatically converts this to an arbitrary string-string map. | ||
| // https://github.com/kubernetes-sigs/controller-tools/issues/385 | ||
| // | ||
| // Active discussion about inclusion of this field in the spec is happening in this PR: | ||
| // https://github.com/kubernetes-sigs/controller-tools/pull/395 | ||
| // | ||
| // Until this is allowed, or if it never is, we will produce a subset of the object meta | ||
| // that contains only the fields which the user is allowed to modify in the metadata. | ||
| type PartialObjectMeta struct { | ||
| // Name must be unique within a namespace. Is required when creating resources, although | ||
| // some resources may allow a client to request the generation of an appropriate name | ||
| // automatically. Name is primarily intended for creation idempotence and configuration | ||
| // definition. | ||
| // Cannot be updated. | ||
| // More info: http://kubernetes.io/docs/user-guide/identifiers#names | ||
| // +optional | ||
| Name string `json:"name,omitempty" protobuf:"bytes,1,opt,name=name"` | ||
|
|
||
| // GenerateName is an optional prefix, used by the server, to generate a unique | ||
| // name ONLY IF the Name field has not been provided. | ||
| // If this field is used, the name returned to the client will be different | ||
| // than the name passed. This value will also be combined with a unique suffix. | ||
| // The provided value has the same validation rules as the Name field, | ||
| // and may be truncated by the length of the suffix required to make the value | ||
| // unique on the server. | ||
| // | ||
| // If this field is specified and the generated name exists, the server will | ||
| // NOT return a 409 - instead, it will either return 201 Created or 500 with Reason | ||
| // ServerTimeout indicating a unique name could not be found in the time allotted, and the client | ||
| // should retry (optionally after the time indicated in the Retry-After header). | ||
| // | ||
| // Applied only if Name is not specified. | ||
| // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#idempotency | ||
| // +optional | ||
| GenerateName string `json:"generateName,omitempty" protobuf:"bytes,2,opt,name=generateName"` | ||
|
|
||
| // Namespace defines the space within each name must be unique. An empty namespace is | ||
| // equivalent to the "default" namespace, but "default" is the canonical representation. | ||
| // Not all objects are required to be scoped to a namespace - the value of this field for | ||
| // those objects will be empty. | ||
| // | ||
| // Must be a DNS_LABEL. | ||
| // Cannot be updated. | ||
| // More info: http://kubernetes.io/docs/user-guide/namespaces | ||
| // +optional | ||
| Namespace string `json:"namespace,omitempty" protobuf:"bytes,3,opt,name=namespace"` | ||
|
|
||
| // Map of string keys and values that can be used to organize and categorize | ||
| // (scope and select) objects. May match selectors of replication controllers | ||
| // and services. | ||
| // More info: http://kubernetes.io/docs/user-guide/labels | ||
| // +optional | ||
| Labels map[string]string `json:"labels,omitempty" protobuf:"bytes,4,rep,name=labels"` | ||
|
|
||
| // Annotations is an unstructured key value map stored with a resource that may be | ||
| // set by external tools to store and retrieve arbitrary metadata. They are not | ||
| // queryable and should be preserved when modifying objects. | ||
| // More info: http://kubernetes.io/docs/user-guide/annotations | ||
| // +optional | ||
| Annotations map[string]string `json:"annotations,omitempty" protobuf:"bytes,5,rep,name=annotations"` | ||
|
|
||
| // List of objects depended by this object. If ALL objects in the list have | ||
| // been deleted, this object will be garbage collected. If this object is managed by a controller, | ||
| // then an entry in this list will point to this controller, with the controller field set to true. | ||
| // There cannot be more than one managing controller. | ||
| // +optional | ||
| // +patchMergeKey=uid | ||
| // +patchStrategy=merge | ||
| OwnerReferences []metav1.OwnerReference `json:"ownerReferences,omitempty" patchStrategy:"merge" patchMergeKey:"uid" protobuf:"bytes,6,rep,name=ownerReferences"` | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Been thinking more about this annotation and whether we really need it. I'm not so sure we do, at least in a boolean form. A couple questions that highlight my concerns:
If this annotation is not present on a CR, what does that mean?
Above, it states "If this annotation is set to false on a CR, that means the user expects the ACK service controller to create the backend AWS service API resource." But this isn't really true, right? It's not the annotation's presence or lack of presence that dictates whether the service controller takes some action. Instead, it's the creation of an
AdoptedResourceCR explicitly by the Kubernetes user that is the signal for a service controller to grab the latest observed state of the referred-to resource instead of calling the API's Create operation.Given 2), would it make more sense to add an annotation called
services.k8s.aws/adopted-onthat is a timestamp of when theAdoptedResourceReconcilersuccessfully created the resource CR after pulling the latest observed state from the AWS API?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I could see more value in this becoming a timestamp. It was initially a boolean so that you could easily run a filter of
services.k8s.aws/adopted=='true'on all resource annotations, but I understand that timestamp probably provide that plus more.This annotation isn't being used by any system, it really is just informational to the user.