Skip to content

Commit 8cff8f7

Browse files
authored
Merge pull request #2 from RedbackThomson/resource-adoption
Create adoption reconciler
2 parents eabde5a + ebb0160 commit 8cff8f7

30 files changed

+1438
-67
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"). You may
4+
// not use this file except in compliance with the License. A copy of the
5+
// License is located at
6+
//
7+
// http://aws.amazon.com/apache2.0/
8+
//
9+
// or in the "license" file accompanying this file. This file is distributed
10+
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
// express or implied. See the License for the specific language governing
12+
// permissions and limitations under the License.
13+
14+
package v1alpha1
15+
16+
import (
17+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
18+
)
19+
20+
// AdoptedResourceSpec defines the desired state of the AdoptedResource.
21+
type AdoptedResourceSpec struct {
22+
// +kubebuilder:validation:Required
23+
Kubernetes *TargetKubernetesResource `json:"kubernetes"`
24+
// +kubebuilder:validation:Required
25+
AWS *AWSIdentifiers `json:"aws"`
26+
}
27+
28+
// AdoptedResourceStatus defines the observed status of the AdoptedResource.
29+
type AdoptedResourceStatus struct {
30+
// A collection of `ackv1alpha1.Condition` objects that describe the various
31+
// terminal states of the adopted resource CR and its target custom resource
32+
Conditions []*Condition `json:"conditions"`
33+
}
34+
35+
// AdoptedResource is the schema for the AdoptedResource API.
36+
// +kubebuilder:object:root=true
37+
// +kubebuilder:subresource:status
38+
type AdoptedResource struct {
39+
metav1.TypeMeta `json:",inline"`
40+
metav1.ObjectMeta `json:"metadata,omitempty"`
41+
Spec AdoptedResourceSpec `json:"spec,omitempty"`
42+
Status AdoptedResourceStatus `json:"status,omitempty"`
43+
}
44+
45+
// AdoptedResourceList defines a list of AdoptedResources.
46+
// +kubebuilder:object:root=true
47+
// +kubebuilder:printcolumn:name="AdoptionStatus",type=string,JSONPath=`.status.adoptionStatus`
48+
type AdoptedResourceList struct {
49+
metav1.TypeMeta `json:",inline"`
50+
metav1.ListMeta `json:"metadata,omitempty"`
51+
Items []AdoptedResource `json:"items"`
52+
}
53+
54+
func init() {
55+
SchemeBuilder.Register(&AdoptedResource{}, &AdoptedResourceList{})
56+
}

apis/core/v1alpha1/annotations.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@ package v1alpha1
1616
const (
1717
// AnnotationPrefix is the prefix for all ACK annotations
1818
AnnotationPrefix = "services.k8s.aws/"
19-
// AnnotationARN is an annotation whose value is an Amazon Resource Name,
20-
// which is a globally-unique identifier, for the backend AWS service API
21-
// resource. If this annotation is SET on a CR, that means the user is
19+
// AnnotationAdopted is an annotation whose value is a boolean value,
20+
// If this annotation is set to true on a CR, that means the user is
2221
// indicating to the ACK service controller that it should expect a backend
2322
// AWS service API resource to already exist (and that ACK should "adopt"
24-
// the resource into its management). If this annotation is NOT SET on a
25-
// CR, that means the user expects the ACK service controller to create the
26-
// backend AWS service API resource.
27-
AnnotationARN = AnnotationPrefix + "arn"
23+
// the resource into its management). If this annotation is set to false on
24+
// a CR, that means the user expects the ACK service controller to create
25+
// the backend AWS service API resource.
26+
AnnotationAdopted = AnnotationPrefix + "adopted"
2827
// AnnotationOwnerAccountID is an annotation whose value is the identifier
2928
// for the AWS account to which the resource belongs. If this annotation
3029
// is set on a CR, the Kubernetes user is indicating that the ACK service

apis/core/v1alpha1/conditions.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ import (
2323
type ConditionType string
2424

2525
const (
26+
// ConditionTypeAdopted indicates that the adopted resource custom resource
27+
// has been successfully reconciled and the target has been created
28+
ConditionTypeAdopted ConditionType = "ACK.Adopted"
2629
// ConditionTypeResourceSynced indicates the state of the resource in the
2730
// backend service is in sync with the ACK service controller
2831
ConditionTypeResourceSynced ConditionType = "ACK.ResourceSynced"
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"). You may
4+
// not use this file except in compliance with the License. A copy of the
5+
// License is located at
6+
//
7+
// http://aws.amazon.com/apache2.0/
8+
//
9+
// or in the "license" file accompanying this file. This file is distributed
10+
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
// express or implied. See the License for the specific language governing
12+
// permissions and limitations under the License.
13+
14+
package v1alpha1
15+
16+
import (
17+
"k8s.io/apimachinery/pkg/runtime/schema"
18+
"sigs.k8s.io/controller-runtime/pkg/scheme"
19+
)
20+
21+
var (
22+
// GroupVersion is the API Group Version used to register the objects
23+
GroupVersion = schema.GroupVersion{Group: "services.k8s.aws", Version: "v1alpha1"}
24+
25+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
26+
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
27+
28+
// AddToScheme adds the types in this group-version to the given scheme.
29+
AddToScheme = SchemeBuilder.AddToScheme
30+
)

apis/core/v1alpha1/identifiers.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"). You may
4+
// not use this file except in compliance with the License. A copy of the
5+
// License is located at
6+
//
7+
// http://aws.amazon.com/apache2.0/
8+
//
9+
// or in the "license" file accompanying this file. This file is distributed
10+
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
// express or implied. See the License for the specific language governing
12+
// permissions and limitations under the License.
13+
14+
package v1alpha1
15+
16+
// AWSIdentifiers provide all unique ways to reference an AWS resource.
17+
type AWSIdentifiers struct {
18+
// ARN is the AWS Resource Name for the resource. It is a globally
19+
// unique identifier.
20+
ARN *AWSResourceName `json:"arn,omitempty"`
21+
// NameOrId is a user-supplied string identifier for the resource. It may
22+
// or may not be globally unique, depending on the type of resource.
23+
NameOrID *string `json:"nameOrID,omitempty"`
24+
}
25+
26+
// TargetKubernetesResource provides all the values necessary to identify a given ACK type
27+
// and override any metadata values when creating a resource of that type.
28+
type TargetKubernetesResource struct {
29+
// +kubebuilder:validation:Required
30+
Group *string `json:"group"`
31+
// +kubebuilder:validation:Required
32+
Kind *string `json:"kind"`
33+
Metadata *PartialObjectMeta `json:"metadata,omitempty"`
34+
}

apis/core/v1alpha1/types.go

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"). You may
4+
// not use this file except in compliance with the License. A copy of the
5+
// License is located at
6+
//
7+
// http://aws.amazon.com/apache2.0/
8+
//
9+
// or in the "license" file accompanying this file. This file is distributed
10+
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
// express or implied. See the License for the specific language governing
12+
// permissions and limitations under the License.
13+
14+
package v1alpha1
15+
16+
import (
17+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
18+
)
19+
20+
// ObjectMeta is metadata that all persisted resources must have, which includes all objects
21+
// users must create.
22+
// It is not possible to use `metav1.ObjectMeta` inside spec, as the controller-gen
23+
// automatically converts this to an arbitrary string-string map.
24+
// https://github.com/kubernetes-sigs/controller-tools/issues/385
25+
//
26+
// Active discussion about inclusion of this field in the spec is happening in this PR:
27+
// https://github.com/kubernetes-sigs/controller-tools/pull/395
28+
//
29+
// Until this is allowed, or if it never is, we will produce a subset of the object meta
30+
// that contains only the fields which the user is allowed to modify in the metadata.
31+
type PartialObjectMeta struct {
32+
// Name must be unique within a namespace. Is required when creating resources, although
33+
// some resources may allow a client to request the generation of an appropriate name
34+
// automatically. Name is primarily intended for creation idempotence and configuration
35+
// definition.
36+
// Cannot be updated.
37+
// More info: http://kubernetes.io/docs/user-guide/identifiers#names
38+
// +optional
39+
Name string `json:"name,omitempty" protobuf:"bytes,1,opt,name=name"`
40+
41+
// GenerateName is an optional prefix, used by the server, to generate a unique
42+
// name ONLY IF the Name field has not been provided.
43+
// If this field is used, the name returned to the client will be different
44+
// than the name passed. This value will also be combined with a unique suffix.
45+
// The provided value has the same validation rules as the Name field,
46+
// and may be truncated by the length of the suffix required to make the value
47+
// unique on the server.
48+
//
49+
// If this field is specified and the generated name exists, the server will
50+
// NOT return a 409 - instead, it will either return 201 Created or 500 with Reason
51+
// ServerTimeout indicating a unique name could not be found in the time allotted, and the client
52+
// should retry (optionally after the time indicated in the Retry-After header).
53+
//
54+
// Applied only if Name is not specified.
55+
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#idempotency
56+
// +optional
57+
GenerateName string `json:"generateName,omitempty" protobuf:"bytes,2,opt,name=generateName"`
58+
59+
// Namespace defines the space within each name must be unique. An empty namespace is
60+
// equivalent to the "default" namespace, but "default" is the canonical representation.
61+
// Not all objects are required to be scoped to a namespace - the value of this field for
62+
// those objects will be empty.
63+
//
64+
// Must be a DNS_LABEL.
65+
// Cannot be updated.
66+
// More info: http://kubernetes.io/docs/user-guide/namespaces
67+
// +optional
68+
Namespace string `json:"namespace,omitempty" protobuf:"bytes,3,opt,name=namespace"`
69+
70+
// Map of string keys and values that can be used to organize and categorize
71+
// (scope and select) objects. May match selectors of replication controllers
72+
// and services.
73+
// More info: http://kubernetes.io/docs/user-guide/labels
74+
// +optional
75+
Labels map[string]string `json:"labels,omitempty" protobuf:"bytes,4,rep,name=labels"`
76+
77+
// Annotations is an unstructured key value map stored with a resource that may be
78+
// set by external tools to store and retrieve arbitrary metadata. They are not
79+
// queryable and should be preserved when modifying objects.
80+
// More info: http://kubernetes.io/docs/user-guide/annotations
81+
// +optional
82+
Annotations map[string]string `json:"annotations,omitempty" protobuf:"bytes,5,rep,name=annotations"`
83+
84+
// List of objects depended by this object. If ALL objects in the list have
85+
// been deleted, this object will be garbage collected. If this object is managed by a controller,
86+
// then an entry in this list will point to this controller, with the controller field set to true.
87+
// There cannot be more than one managing controller.
88+
// +optional
89+
// +patchMergeKey=uid
90+
// +patchStrategy=merge
91+
OwnerReferences []metav1.OwnerReference `json:"ownerReferences,omitempty" patchStrategy:"merge" patchMergeKey:"uid" protobuf:"bytes,6,rep,name=ownerReferences"`
92+
}

0 commit comments

Comments
 (0)