Skip to content

Commit

Permalink
Feat: network load balancer (#179)
Browse files Browse the repository at this point in the history
* feat: network load balancer CRDs and controllers (nlb, forwarding rule, flow log)
  • Loading branch information
cbeti-ionos authored Apr 15, 2024
1 parent 68cb4a0 commit 0d929d9
Show file tree
Hide file tree
Showing 47 changed files with 10,287 additions and 4 deletions.
2 changes: 2 additions & 0 deletions apis/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
mongov1alpha1 "github.com/ionos-cloud/crossplane-provider-ionoscloud/apis/dbaas/mongo/v1alpha1"
postgresv1alpha1 "github.com/ionos-cloud/crossplane-provider-ionoscloud/apis/dbaas/postgres/v1alpha1"
k8sv1alpha1 "github.com/ionos-cloud/crossplane-provider-ionoscloud/apis/k8s/v1alpha1"
nlbv1alpha1 "github.com/ionos-cloud/crossplane-provider-ionoscloud/apis/nlb/v1alpha1"
templatev1alpha1 "github.com/ionos-cloud/crossplane-provider-ionoscloud/apis/v1alpha1"
)

Expand All @@ -41,6 +42,7 @@ func init() {
albv1alpha1.SchemeBuilder.AddToScheme,
backupv1alpha1.SchemeBuilder.AddToScheme,
dataplatformv1alpha1.SchemeBuilder.AddToScheme,
nlbv1alpha1.SchemeBuilder.AddToScheme,
)
}

Expand Down
18 changes: 18 additions & 0 deletions apis/nlb/nlb.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
Copyright 2020 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 nlb contains group Sample API versions
package nlb
65 changes: 65 additions & 0 deletions apis/nlb/v1alpha1/dependencies.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package v1alpha1

import xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"

// LanConfig is used by resources that need to link lans via id or via reference.
type LanConfig struct {
// LanID is the ID of the Lan on which the resource will be created.
// It needs to be provided directly or via reference.
//
// +immutable
// +crossplane:generate:reference:type=github.com/ionos-cloud/crossplane-provider-ionoscloud/apis/compute/v1alpha1.Lan
// +crossplane:generate:reference:extractor=github.com/ionos-cloud/crossplane-provider-ionoscloud/apis/compute/v1alpha1.ExtractLanID()
LanID string `json:"lanId,omitempty"`
// LanIDRef references to a Lan to retrieve its ID.
//
// +optional
// +immutable
LanIDRef *xpv1.Reference `json:"lanIdRef,omitempty"`
// LanIDSelector selects reference to a Lan to retrieve its LanID.
//
// +optional
LanIDSelector *xpv1.Selector `json:"lanIdSelector,omitempty"`
}

// IPBlockConfig used by resources that need to link IPBlocks via id or via reference
type IPBlockConfig struct {
// IPBlockID is the ID of the IPBlock on which the resource will be created.
// It needs to be provided directly or via reference.
//
// +immutable
// +kubebuilder:validation:Format=uuid
// +crossplane:generate:reference:type=github.com/ionos-cloud/crossplane-provider-ionoscloud/apis/compute/v1alpha1.IPBlock
// +crossplane:generate:reference:extractor=github.com/ionos-cloud/crossplane-provider-ionoscloud/apis/compute/v1alpha1.ExtractIPBlockID()
IPBlockID string `json:"ipBlockId,omitempty"`
// IPBlockIDRef references to a IPBlock to retrieve its ID.
//
// +optional
// +immutable
IPBlockIDRef *xpv1.Reference `json:"ipBlockIdRef,omitempty"`
// IPBlockIDSelector selects reference to a IPBlock to retrieve its IPBlockID.
//
// +optional
IPBlockIDSelector *xpv1.Selector `json:"ipBlockIdSelector,omitempty"`
}

// DatacenterConfig is used by resources that need to link datacenters via id or via reference.
type DatacenterConfig struct {
// DatacenterID is the ID of the Datacenter on which the resource should have access.
// It needs to be provided directly or via reference.
//
// +immutable
// +kubebuilder:validation:Format=uuid
// +crossplane:generate:reference:type=github.com/ionos-cloud/crossplane-provider-ionoscloud/apis/compute/v1alpha1.Datacenter
// +crossplane:generate:reference:extractor=github.com/ionos-cloud/crossplane-provider-ionoscloud/apis/compute/v1alpha1.ExtractDatacenterID()
DatacenterID string `json:"datacenterId,omitempty"`
// DatacenterIDRef references to a Datacenter to retrieve its ID.
//
// +optional
// +immutable
DatacenterIDRef *xpv1.Reference `json:"datacenterIdRef,omitempty"`
// DatacenterIDSelector selects reference to a Datacenter to retrieve its DatacenterID.
//
// +optional
DatacenterIDSelector *xpv1.Selector `json:"datacenterIdSelector,omitempty"`
}
137 changes: 137 additions & 0 deletions apis/nlb/v1alpha1/flowlog_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package v1alpha1

import (
"reflect"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"

xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"
)

// FlowLogParameters are the observable fields of a Network Load Balancer FlowLog.
// Required fields in order to create a Network Load Balancer FlowLog:
// DatacenterCfg (via ID or via reference),
// NLBCfg (via ID or via reference),
// Name,
// Action
// Direction.
// Bucket.
type FlowLogParameters struct {
// Datacenter in which the Network Load Balancer that this Flow Log applies to is provisioned in.
//
// +immutable
// +kubebuilder:validation:Required
DatacenterCfg DatacenterConfig `json:"datacenterConfig"`
// NetworkLoadBalancer to which this Flow Log will apply. There can only be one flow log per Network Load Balancer.
//
// +immutable
// +kubebuilder:validation:Required
NLBCfg NetworkLoadBalancerConfig `json:"networkLoadBalancerConfig"`
// Name of the Flow Log.
//
// +kubebuilder:validation:Required
Name string `json:"name"`
// Action specifies the traffic action pattern, accepted values: ACCEPTED, REJECTED, ALL
//
// +kubebuilder:validation:Enum=ACCEPTED;REJECTED;ALL
// +kubebuilder:validation:Required
Action string `json:"action"`
// Direction specifies the traffic action pattern, accepted values: INGRESS, EGRESS, BIDIRECTIONAL
//
// +kubebuilder:validation:Enum=INGRESS;EGRESS;BIDIRECTIONAL
// +kubebuilder:validation:Required
Direction string `json:"direction"`
// Bucket name of an existing IONOS Cloud S3 bucket
//
// +kubebuilder:validation:Required
Bucket string `json:"bucket"`
}

// FlowLogObservation are the observable fields of a Network Load Balancer FlowLog.
type FlowLogObservation struct {
FlowLogID string `json:"flowLogId,omitempty"`
State string `json:"state,omitempty"`
}

// FlowLogSpec defines the desired state of a Network Load Balancer FlowLog.
type FlowLogSpec struct {
xpv1.ResourceSpec `json:",inline"`
ForProvider FlowLogParameters `json:"forProvider"`
}

// FlowLogStatus represents the observed state of a Network Load Balancer FlowLog.
type FlowLogStatus struct {
xpv1.ResourceStatus `json:",inline"`
AtProvider FlowLogObservation `json:"atProvider,omitempty"`
}

// +kubebuilder:object:root=true

// An FlowLog is an example API type.
// +kubebuilder:printcolumn:name="READY",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].status"
// +kubebuilder:printcolumn:name="SYNCED",type="string",JSONPath=".status.conditions[?(@.type=='Synced')].status"
// +kubebuilder:printcolumn:name="DATACENTER ID",type="string",JSONPath=".spec.forProvider.datacenterConfig.datacenterId"
// +kubebuilder:printcolumn:name="NETWORKLOADBALANCER ID",type="string",JSONPath=".spec.forProvider.networkLoadBalancerConfig.networkLoadBalancerId"
// +kubebuilder:printcolumn:name="FLOWLOG ID",type="string",JSONPath=".metadata.annotations.crossplane\\.io/external-name"
// +kubebuilder:printcolumn:name="FLOWLOG NAME",type="string",JSONPath=".spec.forProvider.name"
// +kubebuilder:printcolumn:name="ACTION",type="string",JSONPath=".spec.forProvider.action"
// +kubebuilder:printcolumn:name="DIRECTION",type="string",JSONPath=".spec.forProvider.direction"
// +kubebuilder:printcolumn:name="S3BUCKET",type="string",JSONPath=".spec.forProvider.bucket"
// +kubebuilder:printcolumn:name="STATE",type="string",JSONPath=".status.atProvider.state"
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp"
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster,categories={crossplane,managed,ionoscloud}
type FlowLog struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec FlowLogSpec `json:"spec"`
Status FlowLogStatus `json:"status,omitempty"`
}

// GetFlowLogName returns the name of the flow log
func (f *FlowLog) GetFlowLogName() string {
return f.Spec.ForProvider.Name
}

// GetAction returns the action of the flow log
func (f *FlowLog) GetAction() string {
return f.Spec.ForProvider.Action
}

// GetDirection returns the direction of the flow log
func (f *FlowLog) GetDirection() string {
return f.Spec.ForProvider.Direction
}

// GetBucket returns the bucket of the flow log
func (f *FlowLog) GetBucket() string {
return f.Spec.ForProvider.Bucket
}

// SetState sets the state of the flow log observation
func (f *FlowLog) SetState(state string) {
f.Status.AtProvider.State = state
}

// +kubebuilder:object:root=true

// FlowLogList contains a list of NetworkLoadBalancer
type FlowLogList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []FlowLog `json:"items"`
}

// NetworkLoadBalancer type metadata.
var (
FlowLogKind = reflect.TypeOf(FlowLog{}).Name()
FlowLogGroupKind = schema.GroupKind{Group: Group, Kind: FlowLogKind}.String()
FlowLogKindAPIVersion = FlowLogKind + "." + SchemeGroupVersion.String()
FlowLogGroupVersionKind = SchemeGroupVersion.WithKind(FlowLogKind)
)

func init() {
SchemeBuilder.Register(&FlowLog{}, &FlowLogList{})
}
Loading

0 comments on commit 0d929d9

Please sign in to comment.