Skip to content

Commit

Permalink
chore: annotate KGO supported types
Browse files Browse the repository at this point in the history
  • Loading branch information
czeslavo committed Oct 3, 2024
1 parent 7a90c9a commit eb35872
Show file tree
Hide file tree
Showing 40 changed files with 207 additions and 62 deletions.
2 changes: 2 additions & 0 deletions api/configuration/v1/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package v1

// ConditionType is a type of condition associated with an object.
// This type should be used with the object's Status.Conditions field.
// +kgosupported
type ConditionType string

// ConditionReason defines the set of reasons that explain why a particular
// condition type has been raised.
// +kgosupported
type ConditionReason string

const (
Expand Down
6 changes: 6 additions & 0 deletions api/configuration/v1/configsource.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v1

// ConfigSource is a wrapper around SecretValueFromSource.
// +kubebuilder:object:generate=true
// +kgosupported
type ConfigSource struct {
// Specifies a name and a key of a secret to refer to. The namespace is implicitly set to the one of referring object.
SecretValue SecretValueFromSource `json:"secretKeyRef"`
Expand All @@ -11,6 +12,7 @@ type ConfigSource struct {
// It is an equivalent of the following patch:
// `{"op": "add", "path": {.Path}, "value": {.ComputedValueFrom}}`.
// +kubebuilder:object:generate=true
// +kgosupported
type ConfigPatch struct {
// Path is the JSON-Pointer value (RFC6901) that references a location within the target configuration.
Path string `json:"path"`
Expand All @@ -20,6 +22,7 @@ type ConfigPatch struct {

// NamespacedConfigSource is a wrapper around NamespacedSecretValueFromSource.
// +kubebuilder:object:generate=true
// +kgosupported
type NamespacedConfigSource struct {
// Specifies a name, a namespace, and a key of a secret to refer to.
SecretValue NamespacedSecretValueFromSource `json:"secretKeyRef"`
Expand All @@ -28,6 +31,7 @@ type NamespacedConfigSource struct {
// NamespacedConfigPatch is a JSON patch to add values from secrets to KongClusterPlugin
// to the generated configuration of plugin in Kong.
// +kubebuilder:object:generate=true
// +kgosupported
type NamespacedConfigPatch struct {
// Path is the JSON path to add the patch.
Path string `json:"path"`
Expand All @@ -37,6 +41,7 @@ type NamespacedConfigPatch struct {

// SecretValueFromSource represents the source of a secret value.
// +kubebuilder:object:generate=true
// +kgosupported
type SecretValueFromSource struct {
// The secret containing the key.
Secret string `json:"name"`
Expand All @@ -46,6 +51,7 @@ type SecretValueFromSource struct {

// NamespacedSecretValueFromSource represents the source of a secret value specifying the secret namespace.
// +kubebuilder:object:generate=true
// +kgosupported
type NamespacedSecretValueFromSource struct {
// The namespace containing the secret.
Namespace string `json:"namespace"`
Expand Down
11 changes: 7 additions & 4 deletions api/configuration/v1/kongconsumer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
konnectv1alpha1 "github.com/kong/kubernetes-configuration/api/konnect/v1alpha1"
)

// KongConsumer is the Schema for the kongconsumers API.
//
// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:object:root=true
Expand All @@ -36,8 +38,7 @@ import (
// +kubebuilder:validation:XValidation:rule="!has(oldSelf.spec.controlPlaneRef) || has(self.spec.controlPlaneRef)", message="controlPlaneRef is required once set"
// +kubebuilder:validation:XValidation:rule="!has(self.spec.controlPlaneRef.konnectNamespacedRef) ? true : !has(self.spec.controlPlaneRef.konnectNamespacedRef.__namespace__)", message="spec.controlPlaneRef cannot specify namespace for namespaced resource"
// +kubebuilder:validation:XValidation:rule="(!has(self.status) || !self.status.conditions.exists(c, c.type == 'Programmed' && c.status == 'True')) ? true : oldSelf.spec.controlPlaneRef == self.spec.controlPlaneRef", message="spec.controlPlaneRef is immutable when an entity is already Programmed"

// KongConsumer is the Schema for the kongconsumers API.
// +kgosupported
type KongConsumer struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down Expand Up @@ -66,15 +67,17 @@ type KongConsumer struct {
Status KongConsumerStatus `json:"status,omitempty"`
}

// KongConsumerSpec defines the desired state of KongConsumer.
// +kgosupported
type KongConsumerSpec struct {
// ControlPlaneRef is a reference to a ControlPlane this Consumer is associated with.
// +optional
ControlPlaneRef *configurationv1alpha1.ControlPlaneRef `json:"controlPlaneRef,omitempty"`
}

// +kubebuilder:object:root=true

// KongConsumerList contains a list of KongConsumer.
// +kubebuilder:object:root=true
// +kgosupported
type KongConsumerList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Expand Down
10 changes: 6 additions & 4 deletions api/configuration/v1/kongplugin_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// KongPlugin is the Schema for the kongplugins API.
//
// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:object:root=true
Expand All @@ -36,8 +38,7 @@ import (
// +kubebuilder:validation:XValidation:rule="!(has(self.config) && has(self.configFrom))", message="Using both config and configFrom fields is not allowed."
// +kubebuilder:validation:XValidation:rule="!(has(self.configFrom) && has(self.configPatches))", message="Using both configFrom and configPatches fields is not allowed."
// +kubebuilder:validation:XValidation:rule="self.plugin == oldSelf.plugin", message="The plugin field is immutable"

// KongPlugin is the Schema for the kongplugins API.
// +kgosupported
type KongPlugin struct {
metav1.TypeMeta `json:",inline"`
// Setting a `global` label to `true` will apply the plugin to every request proxied by the Kong.
Expand Down Expand Up @@ -100,16 +101,17 @@ type KongPlugin struct {
Status KongPluginStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// KongPluginList contains a list of KongPlugin.
// +kubebuilder:object:root=true
// +kgosupported
type KongPluginList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []KongPlugin `json:"items"`
}

// KongPluginStatus represents the current status of the KongPlugin resource.
// +kgosupported
type KongPluginStatus struct {
// Conditions describe the current conditions of the KongPluginStatus.
//
Expand Down
1 change: 1 addition & 0 deletions api/configuration/v1/kongprotocol_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package v1
// This alias is necessary to deal with https://github.com/kubernetes-sigs/controller-tools/issues/342
// +kubebuilder:validation:Enum=http;https;grpc;grpcs;tcp;tls;udp
// +kubebuilder:object:generate=true
// +kgosupported
type KongProtocol string

// KongProtocolsToStrings converts a slice of KongProtocol to plain strings.
Expand Down
3 changes: 3 additions & 0 deletions api/configuration/v1alpha1/key_set_ref.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v1alpha1

// KeySetRefType is the enum type for the KeySetRef.
// +kubebuilder:validation:Enum=konnectID;namespacedRef
// +kgosupported
type KeySetRefType string

const (
Expand All @@ -19,6 +20,7 @@ const (
// It is used to reference a KeySet entity.
// +kubebuilder:validation:XValidation:rule="self.type == 'namespacedRef' ? has(self.namespacedRef) : true", message="when type is namespacedRef, namespacedRef must be set"
// +kubebuilder:validation:XValidation:rule="self.type == 'konnectID' ? has(self.konnectID) : true", message="when type is konnectID, konnectID must be set"
// +kgosupported
type KeySetRef struct {
// Type defines type of the KeySet object reference. It can be one of:
// - konnectID
Expand All @@ -37,6 +39,7 @@ type KeySetRef struct {
}

// KeySetNamespacedRef is the schema for the KeySetNamespacedRef type.
// +kgosupported
type KeySetNamespacedRef struct {
// Name is the name of the KeySet object.
// +kubebuilder:validation:MinLength=1
Expand Down
6 changes: 6 additions & 0 deletions api/configuration/v1alpha1/kong_ca_certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
// +kubebuilder:validation:XValidation:rule="!has(oldSelf.spec.controlPlaneRef) || has(self.spec.controlPlaneRef)", message="controlPlaneRef is required once set"
// +kubebuilder:validation:XValidation:rule="!has(self.spec.controlPlaneRef.konnectNamespacedRef) ? true : !has(self.spec.controlPlaneRef.konnectNamespacedRef.__namespace__)", message="spec.controlPlaneRef cannot specify namespace for namespaced resource"
// +kubebuilder:validation:XValidation:rule="(!self.status.conditions.exists(c, c.type == 'Programmed' && c.status == 'True')) ? true : oldSelf.spec.controlPlaneRef == self.spec.controlPlaneRef", message="spec.controlPlaneRef is immutable when an entity is already Programmed"
// +kgosupported
type KongCACertificate struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand All @@ -28,13 +29,15 @@ type KongCACertificate struct {
}

// KongCACertificateSpec contains the specification for the KongCACertificate.
// +kgosupported
type KongCACertificateSpec struct {
// ControlPlaneRef references the Konnect Control Plane that this KongCACertificate should be created in.
ControlPlaneRef *ControlPlaneRef `json:"controlPlaneRef,omitempty"`
KongCACertificateAPISpec `json:",inline"`
}

// KongCACertificateAPISpec contains the API specification for the KongCACertificate.
// +kgosupported
type KongCACertificateAPISpec struct {
// Cert is the PEM-encoded CA certificate.
// +kubebuilder:validation:Required
Expand All @@ -43,6 +46,8 @@ type KongCACertificateAPISpec struct {
Tags []string `json:"tags,omitempty"`
}

// KongCACertificateStatus defines the status for a KongCACertificate.
// +kgosupported
type KongCACertificateStatus struct {
// Konnect contains the Konnect entity status.
// +optional
Expand All @@ -58,6 +63,7 @@ type KongCACertificateStatus struct {

// KongCACertificateList contains a list of KongCACertificates.
// +kubebuilder:object:root=true
// +kgosupported
type KongCACertificateList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Expand Down
6 changes: 6 additions & 0 deletions api/configuration/v1alpha1/kong_certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
// +kubebuilder:printcolumn:name="Programmed",description="The Resource is Programmed on Konnect",type=string,JSONPath=`.status.conditions[?(@.type=='Programmed')].status`
// +kubebuilder:validation:XValidation:rule="!has(oldSelf.spec.controlPlaneRef) || has(self.spec.controlPlaneRef)", message="controlPlaneRef is required once set"
// +kubebuilder:validation:XValidation:rule="(!self.status.conditions.exists(c, c.type == 'Programmed' && c.status == 'True')) ? true : oldSelf.spec.controlPlaneRef == self.spec.controlPlaneRef", message="spec.controlPlaneRef is immutable when an entity is already Programmed"
// +kgosupported
type KongCertificate struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand All @@ -27,13 +28,15 @@ type KongCertificate struct {
}

// KongCertificateSpec contains the specification for the KongCertificate.
// +kgosupported
type KongCertificateSpec struct {
// ControlPlaneRef references the Konnect Control Plane that this KongCertificate should be created in.
ControlPlaneRef *ControlPlaneRef `json:"controlPlaneRef,omitempty"`
KongCertificateAPISpec `json:",inline"`
}

// KongCertificateAPISpec contains the API specification for the KongCertificate.
// +kgosupported
type KongCertificateAPISpec struct {
// Cert is the PEM-encoded certificate.
// +kubebuilder:validation:Required
Expand All @@ -56,6 +59,8 @@ type KongCertificateAPISpec struct {
Tags []string `json:"tags,omitempty"`
}

// KongCertificateStatus defines the status for a KongCertificate.
// +kgosupported
type KongCertificateStatus struct {
// Konnect contains the Konnect entity status.
// +optional
Expand All @@ -71,6 +76,7 @@ type KongCertificateStatus struct {

// KongCertificateList contains a list of KongCertificates.
// +kubebuilder:object:root=true
// +kgosupported
type KongCertificateList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Expand Down
19 changes: 13 additions & 6 deletions api/configuration/v1alpha1/kong_license_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// KongLicense stores a Kong enterprise license to apply to managed Kong gateway instances.
//
// +genclient
// +genclient:nonNamespaced
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand All @@ -13,8 +15,7 @@ import (
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`,description="Age"
// +kubebuilder:printcolumn:name="Enabled",type=boolean,JSONPath=`.enabled`,description="Enabled to configure on Kong gateway instances"

// KongLicense stores a Kong enterprise license to apply to managed Kong gateway instances.
// +kgosupported
type KongLicense struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand All @@ -29,6 +30,7 @@ type KongLicense struct {
}

// KongLicenseStatus stores the status of the KongLicense being processesed in each controller that reconciles it.
// +kgosupported
type KongLicenseStatus struct {
// +listType=map
// +listMapKey=controllerName
Expand All @@ -37,6 +39,7 @@ type KongLicenseStatus struct {

// KongLicenseControllerStatus is the status of owning KongLicense being processed
// identified by the controllerName field.
// +kgosupported
type KongLicenseControllerStatus struct {
// ControllerName is an identifier of the controller to reconcile this KongLicense.
// Should be unique in the list of controller statuses.
Expand All @@ -56,18 +59,21 @@ type KongLicenseControllerStatus struct {
// RFC 1123 subdomain.
// +kubebuilder:validation:MaxLength=253
// +kubebuilder:validation:Pattern=`^$|^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$`
// +kgosupported
type Group string

// Kind refers to a Kubernetes kind.
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=63
// +kubebuilder:validation:Pattern=`^[a-zA-Z]([-a-zA-Z0-9]*[a-zA-Z0-9])?$`
// +kgosupported
type Kind string

// Namespace refers to a Kubernetes namespace. It must be a RFC 1123 label.
// +kubebuilder:validation:Pattern=`^[a-z0-9]([-a-z0-9]*[a-z0-9])?$`
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=63
// +kgosupported
type Namespace string

// ObjectName refers to the name of a Kubernetes object.
Expand All @@ -76,8 +82,11 @@ type Namespace string
//
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=253
// +kgosupported
type ObjectName string

// ControllerReference defines the reference of a controller that reconciles a KongLicense.
// +kgosupported
type ControllerReference struct {
// Group is the group of referent.
// It should be empty if the referent is in "core" group (like pod).
Expand All @@ -92,11 +101,9 @@ type ControllerReference struct {
Name ObjectName `json:"name"`
}

type KongLicensePhase string

// +kubebuilder:object:root=true

// KongLicenseList contains a list of KongLicense.
// +kubebuilder:object:root=true
// +kgosupported
type KongLicenseList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Expand Down
11 changes: 9 additions & 2 deletions api/configuration/v1alpha1/kong_target_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Programmed",description="The Resource is Programmed on Konnect",type=string,JSONPath=`.status.conditions[?(@.type=='Programmed')].status`
// +kubebuilder:validation:XValidation:rule="oldSelf.spec.upstreamRef == self.spec.upstreamRef", message="spec.upstreamRef is immutable"
// +kgosupported
type KongTarget struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand All @@ -41,13 +42,17 @@ type KongTarget struct {
Status KongTargetStatus `json:"status,omitempty"`
}

// KongTargetSpec defines the specification of a Kong Target.
// +kgosupported
type KongTargetSpec struct {
// UpstreamRef is a reference to a KongUpstream this KongTarget is attached to.
UpstreamRef TargetRef `json:"upstreamRef"`
// KongTargetAPISpec are the attributes of the Kong Target itself.
KongTargetAPISpec `json:",inline"`
}

// KongTargetAPISpec defines the attributes of a Kong Target.
// +kgosupported
type KongTargetAPISpec struct {
// Target is the target address of the upstream.
Target string `json:"target"`
Expand All @@ -60,6 +65,8 @@ type KongTargetAPISpec struct {
Tags []string `json:"tags,omitempty"`
}

// KongTargetStatus contains the status of a Kong Target.
// +kgosupported
type KongTargetStatus struct {
// Konnect contains the Konnect entity status.
// +optional
Expand All @@ -73,9 +80,9 @@ type KongTargetStatus struct {
Conditions []metav1.Condition `json:"conditions,omitempty"`
}

// +kubebuilder:object:root=true

// KongTargetList contains a list of Kong Targets.
// +kubebuilder:object:root=true
// +kgosupported
type KongTargetList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Expand Down
Loading

0 comments on commit eb35872

Please sign in to comment.