Skip to content

Commit

Permalink
add Konnect related fields and methods to KongVault (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
randmonkey authored Sep 12, 2024
1 parent 960b674 commit bbebd9d
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 0 deletions.
62 changes: 62 additions & 0 deletions api/configuration/v1alpha1/kong_vault_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package v1alpha1

import (
konnectv1alpha1 "github.com/kong/kubernetes-configuration/api/konnect/v1alpha1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down Expand Up @@ -49,6 +50,58 @@ type KongVault struct {
Status KongVaultStatus `json:"status,omitempty"`
}

// initKonnectStatus initializes the Konnect status of KongVualt when it is empty.
func (v *KongVault) initKonnectStatus() {
v.Status.Konnect = &konnectv1alpha1.KonnectEntityStatusWithControlPlaneRef{}
}

// GetKonnectStatus returns the Konnect status contained in the KongVault status.
func (v *KongVault) GetKonnectStatus() *konnectv1alpha1.KonnectEntityStatus {
if v.Status.Konnect == nil {
return nil
}
return &v.Status.Konnect.KonnectEntityStatus
}

// GetKonnectID returns the Konnect ID in the KongVault status.
func (v *KongVault) GetKonnectID() string {
if v.Status.Konnect == nil {
return ""
}
return v.Status.Konnect.ID
}

// SetKonnectID sets the Konnect ID in the KongVault status.
func (v *KongVault) SetKonnectID(id string) {
if v.Status.Konnect == nil {
v.initKonnectStatus()
}
v.Status.Konnect.ID = id
}

// SetControlPlaneID sets the ControlPlane ID in the KongVault status.
func (v *KongVault) SetControlPlaneID(id string) {
if v.Status.Konnect == nil {
v.initKonnectStatus()
}
v.Status.Konnect.ControlPlaneID = id
}

// GetTypeName returns the KongVault Kind name
func (v KongVault) GetTypeName() string {
return "KongVault"
}

// GetConditions returns the Status Conditions in the KongVault.
func (v *KongVault) GetConditions() []metav1.Condition {
return v.Status.Conditions
}

// SetConditions sets the Status Conditions in the KongVault.
func (v *KongVault) SetConditions(conditions []metav1.Condition) {
v.Status.Conditions = conditions
}

// KongVaultSpec defines specification of a custom Kong vault.
type KongVaultSpec struct {
// Backend is the type of the backend storing the secrets in the vault.
Expand All @@ -64,10 +117,19 @@ type KongVaultSpec struct {
Description string `json:"description,omitempty"`
// Config is the configuration of the vault. Varies for different backends.
Config apiextensionsv1.JSON `json:"config,omitempty"`
// Tags are the tags associated to the vault for grouping and filtering.
Tags []string `json:"tags,omitempty"`
// ControlPlaneRef is a reference to a Konnect ControlPlane this KongVault is associated with.
// +optional
ControlPlaneRef *ControlPlaneRef `json:"controlPlaneRef,omitempty"`
}

// KongVaultStatus represents the current status of the KongVault resource.
type KongVaultStatus struct {
// Konnect contains the Konnect entity status.
// +optional
Konnect *konnectv1alpha1.KonnectEntityStatusWithControlPlaneRef `json:"konnect,omitempty"`

// Conditions describe the current conditions of the KongVaultStatus.
//
// Known condition types are:
Expand Down
15 changes: 15 additions & 0 deletions api/configuration/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 65 additions & 0 deletions config/crd/bases/configuration.konghq.com_kongvaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,44 @@ spec:
description: Config is the configuration of the vault. Varies for
different backends.
x-kubernetes-preserve-unknown-fields: true
controlPlaneRef:
description: ControlPlaneRef is a reference to a Konnect ControlPlane
this KongVault is associated with.
properties:
konnectID:
description: |-
KonnectID is the schema for the KonnectID type.
This field is required when the Type is konnectID.
type: string
konnectNamespacedRef:
description: |-
KonnectNamespacedRef is a reference to a Konnect Control Plane entity inside the cluster.
It contains the name of the Konnect Control Plane.
This field is required when the Type is konnectNamespacedRef.
properties:
name:
description: Name is the name of the Konnect Control Plane.
type: string
required:
- name
type: object
type:
description: |-
Type can be one of:
- konnectID
- konnectNamespacedRef
enum:
- konnectID
- konnectNamespacedRef
type: string
type: object
x-kubernetes-validations:
- message: when type is konnectNamespacedRef, konnectNamespacedRef
must be set
rule: 'self.type == ''konnectNamespacedRef'' ? has(self.konnectNamespacedRef)
: true'
- message: when type is konnectID, konnectID must be set
rule: 'self.type == ''konnectID'' ? has(self.konnectID) : true'
description:
description: Description is the additional information about the vault.
type: string
Expand All @@ -87,6 +125,12 @@ spec:
It is immutable after created.
minLength: 1
type: string
tags:
description: Tags are the tags associated to the vault for grouping
and filtering.
items:
type: string
type: array
required:
- backend
- prefix
Expand Down Expand Up @@ -167,6 +211,27 @@ spec:
x-kubernetes-list-map-keys:
- type
x-kubernetes-list-type: map
konnect:
description: Konnect contains the Konnect entity status.
properties:
controlPlaneID:
description: ControlPlaneID is the Konnect ID of the ControlPlane
this Route is associated with.
type: string
id:
description: |-
ID is the unique identifier of the Konnect entity as assigned by Konnect API.
If it's unset (empty string), it means the Konnect entity hasn't been created yet.
type: string
organizationID:
description: OrgID is ID of Konnect Org that this entity has been
created in.
type: string
serverURL:
description: ServerURL is the URL of the Konnect server in which
the entity exists.
type: string
type: object
required:
- conditions
type: object
Expand Down
3 changes: 3 additions & 0 deletions docs/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ _Appears in:_
- [KongPluginBindingSpec](#kongpluginbindingspec)
- [KongServiceSpec](#kongservicespec)
- [KongUpstreamSpec](#kongupstreamspec)
- [KongVaultSpec](#kongvaultspec)

#### ControllerReference

Expand Down Expand Up @@ -838,6 +839,8 @@ KongVaultSpec defines specification of a custom Kong vault.
| `prefix` _string_ | Prefix is the prefix of vault URI for referencing values in the vault. It is immutable after created. |
| `description` _string_ | Description is the additional information about the vault. |
| `config` _[JSON](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.28/#json-v1-apiextensions-k8s-io)_ | Config is the configuration of the vault. Varies for different backends. |
| `tags` _string array_ | Tags are the tags associated to the vault for grouping and filtering. |
| `controlPlaneRef` _[ControlPlaneRef](#controlplaneref)_ | ControlPlaneRef is a reference to a Konnect ControlPlane this KongVault is associated with. |


_Appears in:_
Expand Down

0 comments on commit bbebd9d

Please sign in to comment.