Skip to content
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

Add ObservedObjectCollection API type #217

Merged
merged 5 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apis/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

objectv1alpha1 "github.com/crossplane-contrib/provider-kubernetes/apis/object/v1alpha1"
objectv1alhpa2 "github.com/crossplane-contrib/provider-kubernetes/apis/object/v1alpha2"
observedobjectcollectionv1alpha1 "github.com/crossplane-contrib/provider-kubernetes/apis/observedobjectcollection/v1alpha1"
templatev1alpha1 "github.com/crossplane-contrib/provider-kubernetes/apis/v1alpha1"
)

Expand All @@ -31,6 +32,7 @@ func init() {
templatev1alpha1.SchemeBuilder.AddToScheme,
objectv1alpha1.SchemeBuilder.AddToScheme,
objectv1alhpa2.SchemeBuilder.AddToScheme,
observedobjectcollectionv1alpha1.SchemeBuilder.AddToScheme,
)
}

Expand Down
22 changes: 22 additions & 0 deletions apis/observedobjectcollection/v1alpha1/doc.go
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
50 changes: 50 additions & 0 deletions apis/observedobjectcollection/v1alpha1/register.go
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{})
}
126 changes: 126 additions & 0 deletions apis/observedobjectcollection/v1alpha1/types.go
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"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need this field in the status? AFAIU, it is always deterministic and we don't have to store this in status.

Copy link
Contributor Author

@pedjak pedjak Apr 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see #217 (comment)

IMHO, instead of relying on a convention, we can make the label discoverable by users.

}

// 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"`
}
Loading
Loading