-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
ObservedObjectCollection
API type (#217)
* Add `ObservedObjectCollection` API type Objects in the collection are defined by: * GVK * optional namespace * label selector The objects are fetched using the specified provider config and for the matched objects the provider creates counterpart observe-only objects in the local cluster. The created objects are owned by the collection resource and reconciled as usual by the provider. They are labeled with a common label, so that they can be fetched easily. The label is discoverable by reading `.status.membershipLabel` field of `ObservedObjectCollection`. Signed-off-by: Predrag Knezevic <[email protected]>
- Loading branch information
Showing
14 changed files
with
1,509 additions
and
473 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
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,22 @@ | ||
/* | ||
Copyright 2024 The Crossplane 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 v1alpha1 contains the v1alpha1 group ObservedObjectCollection resources of the Kubernetes provider. | ||
// +kubebuilder:ac:generate=true | ||
// +kubebuilder:object:generate=true | ||
// +groupName=kubernetes.crossplane.io | ||
// +versionName=v1alpha1 | ||
package v1alpha1 |
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,50 @@ | ||
/* | ||
Copyright 2024 The Crossplane 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 v1alpha1 | ||
|
||
import ( | ||
"reflect" | ||
|
||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"sigs.k8s.io/controller-runtime/pkg/scheme" | ||
) | ||
|
||
// Package type metadata. | ||
const ( | ||
Group = "kubernetes.crossplane.io" | ||
Version = "v1alpha1" | ||
) | ||
|
||
var ( | ||
// SchemeGroupVersion is group version used to register these objects | ||
SchemeGroupVersion = schema.GroupVersion{Group: Group, Version: Version} | ||
|
||
// SchemeBuilder is used to add go types to the GroupVersionKind scheme | ||
SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion} | ||
) | ||
|
||
// ProviderConfig type metadata. | ||
var ( | ||
ObservedObjectCollectionKind = reflect.TypeOf(ObservedObjectCollection{}).Name() | ||
ObservedObjectCollectionGroupKind = schema.GroupKind{Group: Group, Kind: ObservedObjectCollectionKind}.String() | ||
ObservedObjectCollectionAPIVersion = ObservedObjectCollectionKind + "." + SchemeGroupVersion.String() | ||
ObservedObjectCollectionGroupVersionKind = SchemeGroupVersion.WithKind(ObservedObjectCollectionKind) | ||
) | ||
|
||
func init() { | ||
SchemeBuilder.Register(&ObservedObjectCollection{}, &ObservedObjectCollectionList{}) | ||
} |
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,126 @@ | ||
/* | ||
Copyright 2024 The Crossplane 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 v1alpha1 | ||
|
||
import ( | ||
"k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
v12 "github.com/crossplane/crossplane-runtime/apis/common/v1" | ||
) | ||
|
||
// +kubebuilder:object:root=true | ||
|
||
// A ObservedObjectCollection is a provider Kubernetes API type | ||
// +kubebuilder:subresource:status | ||
// +kubebuilder:printcolumn:name="KIND",type="string",JSONPath=".spec.kind" | ||
// +kubebuilder:printcolumn:name="APIVERSION",type="string",JSONPath=".spec.apiVersion",priority=1 | ||
// +kubebuilder:printcolumn:name="PROVIDERCONFIG",type="string",JSONPath=".spec.providerConfigRef.name" | ||
// +kubebuilder:printcolumn:name="SYNCED",type="string",JSONPath=".status.conditions[?(@.type=='Synced')].status" | ||
// +kubebuilder:printcolumn:name="READY",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].status" | ||
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp" | ||
// +kubebuilder:resource:scope=Cluster,categories={crossplane,managed,kubernetes} | ||
// +kubebuilder:validation:XValidation:rule="size(self.metadata.name) < 64",message="metadata.name max length is 63" | ||
type ObservedObjectCollection struct { | ||
v1.TypeMeta `json:",inline"` | ||
v1.ObjectMeta `json:"metadata,omitempty"` | ||
Spec ObservedObjectCollectionSpec `json:"spec"` | ||
Status ObservedObjectCollectionStatus `json:"status,omitempty"` | ||
} | ||
|
||
// +kubebuilder:object:root=true | ||
|
||
// ObservedObjectCollectionList contains a list of ObservedObjectCollection | ||
type ObservedObjectCollectionList struct { | ||
v1.TypeMeta `json:",inline"` | ||
v1.ListMeta `json:"metadata,omitempty"` | ||
Items []ObservedObjectCollection `json:"items"` | ||
} | ||
|
||
// ObservedObjectCollectionSpec defines the desired state of ObservedObjectCollection | ||
type ObservedObjectCollectionSpec struct { | ||
|
||
// ObserveObjects declares what criteria object need to fulfil | ||
// to become a member of this collection | ||
ObserveObjects ObserveObjectCriteria `json:"observeObjects"` | ||
|
||
// ProviderConfigReference specifies how the provider that will be used to | ||
// create, observe, update, and delete this managed resource should be | ||
// configured. | ||
// +kubebuilder:default={"name": "default"} | ||
ProviderConfigReference v12.Reference `json:"providerConfigRef,omitempty"` | ||
|
||
// Template when defined is used for creating Object instances | ||
// +optional | ||
Template *ObservedObjectTemplate `json:"objectTemplate,omitempty"` | ||
} | ||
|
||
// ObserveObjectCriteria declares criteria for an object to be a part of collection | ||
type ObserveObjectCriteria struct { | ||
|
||
// APIVersion of objects that should be matched by the selector | ||
// +kubebuilder:validation:MinLength:=1 | ||
APIVersion string `json:"apiVersion"` | ||
|
||
// Kind of objects that should be matched by the selector | ||
// +kubebuilder:validation:MinLength:=1 | ||
Kind string `json:"kind"` | ||
|
||
// Namespace where to look for objects. | ||
// If omitted, search is performed across all namespaces. | ||
// For cluster-scoped objects, omit it. | ||
// +optional | ||
Namespace string `json:"namespace,omitempty"` | ||
|
||
// Selector defines the criteria for including objects into the collection | ||
Selector v1.LabelSelector `json:"selector"` | ||
} | ||
|
||
// ObservedObjectTemplate represents template used when creating observe-only Objects matching the given selector | ||
type ObservedObjectTemplate struct { | ||
|
||
// Objects metadata | ||
Metadata ObservedObjectTemplateMetadata `json:"metadata,omitempty"` | ||
} | ||
|
||
// ObservedObjectTemplateMetadata represents objects metadata | ||
type ObservedObjectTemplateMetadata struct { | ||
|
||
// Labels of an object | ||
Labels map[string]string `json:"labels,omitempty"` | ||
|
||
// Annotations of an object | ||
Annotations map[string]string `json:"annotations,omitempty"` | ||
} | ||
|
||
// ObservedObjectCollectionStatus represents the observed state of a ObservedObjectCollection | ||
type ObservedObjectCollectionStatus struct { | ||
v12.ResourceStatus `json:",inline"` | ||
|
||
// MembershipLabel is the label set on each member of this collection | ||
// and can be used for fetching them. | ||
// +optional | ||
MembershipLabel map[string]string `json:"membershipLabel,omitempty"` | ||
} | ||
|
||
// ObservedObjectReference represents a reference to Object with ObserveOnly management policy | ||
type ObservedObjectReference struct { | ||
|
||
// Name of the observed object | ||
// +kubebuilder:validation:MinLength:=1 | ||
// +kubebuilder:validation:MaxLength:=253 | ||
Name string `json:"name"` | ||
} |
Oops, something went wrong.