Skip to content

Commit

Permalink
Layer 7 load balancing support for Ingress (#22)
Browse files Browse the repository at this point in the history
* Introduce Addresses API for better handling of endpoint addresses

Signed-off-by: Waleed Malik <[email protected]>

* Implement route controller

Signed-off-by: Waleed Malik <[email protected]>

* Move envoy proxy deployment to envoy CP controller

Signed-off-by: Waleed Malik <[email protected]>

* Update envoy cache based on routes

Signed-off-by: Waleed Malik <[email protected]>

* Fix issues with load balancing

Signed-off-by: Waleed Malik <[email protected]>

* Ensure that listeners for routes are unique

Signed-off-by: Waleed Malik <[email protected]>

* Fixes

Signed-off-by: Waleed Malik <[email protected]>

* Refactored code

Signed-off-by: Waleed Malik <[email protected]>

* Fix tests

Signed-off-by: Waleed Malik <[email protected]>

* Revert local changes

Signed-off-by: Waleed Malik <[email protected]>

* Fix RBAC

Signed-off-by: Waleed Malik <[email protected]>

* rebase

Signed-off-by: Waleed Malik <[email protected]>

* Refactored code

Signed-off-by: Waleed Malik <[email protected]>

---------

Signed-off-by: Waleed Malik <[email protected]>
  • Loading branch information
ahmedwaleedmalik authored Jul 18, 2024
1 parent 76c1a7c commit a8fd791
Show file tree
Hide file tree
Showing 50 changed files with 2,980 additions and 670 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@

# Code
/docs

/bin
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ _build
/bin
cover.out
charts/*/Chart.lock
kubelb-*.tgz
kubelb-*.tgz
__debug*
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ clean: ## Clean binaries

.PHONY: test
test: envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./internal/... -coverprofile cover.out
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test -v ./internal/... -coverprofile cover.out

##@ Build

Expand Down
57 changes: 57 additions & 0 deletions api/kubelb.k8c.io/v1alpha1/addresses_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
Copyright 2024 The KubeLB 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 (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// AddressesSpec defines the desired state of Addresses
type AddressesSpec struct {
// Addresses contains a list of addresses.
//+kubebuilder:validation:MinItems:=1
Addresses []EndpointAddress `json:"addresses,omitempty" protobuf:"bytes,1,rep,name=addresses"`
}

// AddressesStatus defines the observed state of Addresses
type AddressesStatus struct {
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status

// Addresses is the Schema for the addresses API
type Addresses struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec AddressesSpec `json:"spec,omitempty"`
Status AddressesStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&Addresses{}, &AddressesList{})
}
12 changes: 12 additions & 0 deletions api/kubelb.k8c.io/v1alpha1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ package v1alpha1

import corev1 "k8s.io/api/core/v1"

const (
// DefaultAddressName is the default name for the Addresses object.
DefaultAddressName = "default"
)

// LoadBalancerEndpoints is a group of addresses with a common set of ports. The
// expanded set of endpoints is the Cartesian product of Addresses x Ports.
// For example, given:
Expand All @@ -40,7 +45,14 @@ type LoadBalancerEndpoints struct {
//+kubebuilder:validation:MinItems:=1
Addresses []EndpointAddress `json:"addresses,omitempty" protobuf:"bytes,1,rep,name=addresses"`

// AddressesReference is a reference to the Addresses object that contains the IP addresses.
// If this field is set, the Addresses field will be ignored.
// +optional
AddressesReference *corev1.ObjectReference `json:"addressesReference,omitempty" protobuf:"bytes,2,opt,name=addressesReference"`

// Port numbers available on the related IP addresses.
// This field is ignored for routes that are using kubernetes resources as the source.
// +optional
//+kubebuilder:validation:MinItems=1
Ports []EndpointPort `json:"ports,omitempty" protobuf:"bytes,3,rep,name=ports"`
}
Expand Down
5 changes: 5 additions & 0 deletions api/kubelb.k8c.io/v1alpha1/config_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ type ConfigSpec struct {
// PropagateAllAnnotations defines whether all annotations will be propagated to the LoadBalancer service. If set to true, PropagatedAnnotations will be ignored.
// +optional
PropagateAllAnnotations bool `json:"propagateAllAnnotations,omitempty"`

// IngressClassName is the name of the IngressClass that will be used for the routes created by KubeLB. If not specified, KubeLB will replace the IngressClassName
// with an empty value in the Ingress resource which would result in the default IngressClass being used.
// +optional
IngressClassName *string `json:"ingressClassName,omitempty"`
}

// EnvoyProxy defines the desired state of the EnvoyProxy
Expand Down
2 changes: 0 additions & 2 deletions api/kubelb.k8c.io/v1alpha1/loadbalancer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import (
// To configure multiple different annotations, you can provide unique suffix e.g. "kubelb.k8c.io/propagate-annotation-1"
var PropagateAnnotation = "kubelb.k8c.io/propagate-annotation"

// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// LoadBalancerStatus defines the observed state of LoadBalancer
type LoadBalancerStatus struct {
// LoadBalancer contains the current status of the load-balancer,
Expand Down
51 changes: 51 additions & 0 deletions api/kubelb.k8c.io/v1alpha1/route_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
runtime "k8s.io/apimachinery/pkg/runtime"
gwapiv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
)

Expand All @@ -37,6 +38,7 @@ type RouteSpec struct {

type RouteSource struct {
// Kubernetes contains the information about the Kubernetes source.
// This field is automatically populated by the KubeLB CCM and in most cases, users should not set this field manually.
Kubernetes *KubernetesSource `json:"kubernetes,omitempty"`
}

Expand Down Expand Up @@ -104,6 +106,55 @@ type Route struct {

// RouteStatus defines the observed state of the Route.
type RouteStatus struct {
// Resources contains the list of resources that are created/processed as a result of the Route.
Resources RouteResourcesStatus `json:"resources,omitempty"`
}

type RouteResourcesStatus struct {
Source string `json:"source,omitempty"`

Services map[string]RouteServiceStatus `json:"services,omitempty"`

ReferenceGrants map[string]ResourceState `json:"referenceGrants,omitempty"`

Route ResourceState `json:"route,omitempty"`
}

type RouteServiceStatus struct {
ResourceState `json:",inline"`
Ports []corev1.ServicePort `json:"ports,omitempty"`
}

type ResourceState struct {
// APIVersion is the API version of the resource.
APIVersion string `json:"apiVersion,omitempty"`

// Kind is the kind of the resource.
Kind string `json:"kind,omitempty"`

// Name is the name of the resource.
Name string `json:"name,omitempty"`

// Namespace is the namespace of the resource.
Namespace string `json:"namespace,omitempty"`

// GeneratedName is the generated name of the resource.
GeneratedName string `json:"generatedName,omitempty"`

// Status is the actual status of the resource.
Status runtime.RawExtension `json:"status,omitempty"`

Conditions []metav1.Condition `json:"conditions,omitempty"`
}

type ConditionType string

const (
ConditionResourceAppliedSuccessfully ConditionType = "ResourceAppliedSuccessfully"
)

func (t ConditionType) String() string {
return string(t)
}

//+kubebuilder:object:root=true
Expand Down
Loading

0 comments on commit a8fd791

Please sign in to comment.