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

feat(crd): add CredentialBasicAuth #83

Merged
merged 3 commits into from
Sep 19, 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
160 changes: 160 additions & 0 deletions api/configuration/v1alpha1/credential_basic_auth_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
/*
Copyright 2024 Kong, Inc.

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 (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

konnectv1alpha1 "github.com/kong/kubernetes-configuration/api/konnect/v1alpha1"
)

// CredentialBasicAuth is the schema for BasicAuth credentials API which defines a BasicAuth credential for consumers.
//
// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:object:root=true
// +kubebuilder:resource:scope=Namespaced
// +kubebuilder:storageversion
// +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="!has(oldSelf.spec.consumerRef) || has(self.spec.consumerRef)",message="consumerRef is required once set"
// +kubebuilder:validation:XValidation:rule="(!self.status.conditions.exists(c, c.type == 'Programmed' && c.status == 'True')) ? true : oldSelf.spec.consumerRef == self.spec.consumerRef",message="spec.consumerRef is immutable when an entity is already Programmed"
type CredentialBasicAuth struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

// Spec contains the BasicAuth credential specification.
Spec CredentialBasicAuthSpec `json:"spec"`

// Status contains the BasicAuth credential status.
//
// +kubebuilder:default={conditions: {{type: "Programmed", status: "Unknown", reason:"Pending", message:"Waiting for controller", lastTransitionTime: "1970-01-01T00:00:00Z"}}}
Status CredentialBasicAuthStatus `json:"status,omitempty"`
}

func (s *CredentialBasicAuth) initKonnectStatus() {
s.Status.Konnect = &konnectv1alpha1.KonnectEntityStatusWithControlPlaneAndConsumerRefs{}
}

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

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

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

// GetControlPlaneID returns the ControlPlane ID in the CredentialBasicAuth status.
func (s *CredentialBasicAuth) GetControlPlaneID() string {
if s.Status.Konnect == nil {
return ""
}
return s.Status.Konnect.ControlPlaneID
}

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

// GetTypeName returns the CredentialBasicAuth Kind name
func (s CredentialBasicAuth) GetTypeName() string {
return "CredentialBasicAuth"
}

// GetConditions returns the Status Conditions
func (s *CredentialBasicAuth) GetConditions() []metav1.Condition {
return s.Status.Conditions
}

// SetConditions sets the Status Conditions
func (s *CredentialBasicAuth) SetConditions(conditions []metav1.Condition) {
s.Status.Conditions = conditions
}

// CredentialBasicAuthSpec defines specification of a Kong Route.
type CredentialBasicAuthSpec struct {
// ConsumerRef is a reference to a Consumer this CredentialBasicAuth is associated with.
//
// +kubebuilder:validation:Required
ConsumerRef corev1.LocalObjectReference `json:"consumerRef"`

CredentialBasicAuthAPISpec `json:",inline"`
}

// CredentialBasicAuthAPISpec defines specification of a BasicAuth credential.
type CredentialBasicAuthAPISpec struct {
// Password is the password for the BasicAuth credential.
//
// +kubebuilder:validation:Required
Password string `json:"password"`

// Tags is a list of tags for the BasicAuth credential.
Tags []string `json:"tags,omitempty"`

// Username is the username for the BasicAuth credential.
//
// +kubebuilder:validation:Required
Username string `json:"username"`
}

// CredentialBasicAuthStatus represents the current status of the BasicAuth credential resource.
type CredentialBasicAuthStatus struct {
// Konnect contains the Konnect entity status.
// +optional
Konnect *konnectv1alpha1.KonnectEntityStatusWithControlPlaneAndConsumerRefs `json:"konnect,omitempty"`

// Conditions describe the status of the Konnect entity.
// +listType=map
// +listMapKey=type
// +kubebuilder:validation:MinItems=1
// +kubebuilder:validation:MaxItems=8
Conditions []metav1.Condition `json:"conditions,omitempty"`
}

// +kubebuilder:object:root=true

// CredentialBasicAuthList contains a list of BasicAuth credentials.
type CredentialBasicAuthList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []CredentialBasicAuth `json:"items"`
}

func init() {
SchemeBuilder.Register(&CredentialBasicAuth{}, &CredentialBasicAuthList{})
}
123 changes: 123 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.

34 changes: 32 additions & 2 deletions api/konnect/v1alpha1/konnect_entity_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,46 @@ type KonnectEntityStatusWithControlPlaneRef struct {
ControlPlaneID string `json:"controlPlaneID,omitempty"`
}

// SetServerURL sets the server URL of the KonnectEntityStatus struct.
// SetControlPlaneID sets the ControlPlane ID of the KonnectEntityStatus struct.
func (in *KonnectEntityStatusWithControlPlaneRef) SetControlPlaneID(id string) {
in.ControlPlaneID = id
}

// GetServerURL sets the server URL of the KonnectEntityStatus struct.
// GetControlPlaneID sets the ControlPlane ID of the KonnectEntityStatus struct.
func (in *KonnectEntityStatusWithControlPlaneRef) GetControlPlaneID() string {
return in.ControlPlaneID
}

type KonnectEntityStatusWithControlPlaneAndConsumerRefs struct {
KonnectEntityStatus `json:",inline"`

// ControlPlaneID is the Konnect ID of the ControlPlane this Route is associated with.
ControlPlaneID string `json:"controlPlaneID,omitempty"`

// ConsumerID is the Konnect ID of the Consumer this entity is associated with.
ConsumerID string `json:"consumerID,omitempty"`
}

// SetControlPlaneID sets the ControlPlane ID of the KonnectEntityStatus struct.
func (in *KonnectEntityStatusWithControlPlaneAndConsumerRefs) SetControlPlaneID(id string) {
in.ControlPlaneID = id
}

// GetControlPlaneID sets the ControlPlane ID of the KonnectEntityStatus struct.
func (in *KonnectEntityStatusWithControlPlaneAndConsumerRefs) GetControlPlaneID() string {
return in.ControlPlaneID
}

// SetConsumerID sets the Consumer ID of the KonnectEntityStatus struct.
func (in *KonnectEntityStatusWithControlPlaneAndConsumerRefs) SetConsumerID(id string) {
in.ConsumerID = id
}

// GetConsumerID sets the Consumer ID of the KonnectEntityStatus struct.
func (in *KonnectEntityStatusWithControlPlaneAndConsumerRefs) GetConsumerID() string {
return in.ConsumerID
}

type KonnectEntityStatusWithControlPlaneAndServiceRefs struct {
KonnectEntityStatus `json:",inline"`

Expand Down
16 changes: 16 additions & 0 deletions api/konnect/v1alpha1/zz_generated.deepcopy.go

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

Loading