Skip to content
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
2 changes: 1 addition & 1 deletion Makefile.expansion
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ ifeq (, $(shell which controller-gen))
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
cd $$CONTROLLER_GEN_TMP_DIR ;\
go mod init tmp ;\
go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.2.5 ;\
go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.9.2 ;\
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
}
CONTROLLER_GEN=$(GOBIN)/controller-gen
Expand Down
12 changes: 12 additions & 0 deletions hack/crd/proxy.kubegateway.io_upstreamclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ spec:
like 0.01 (qps:1, qpsDivisor:100)
format: int32
type: integer
serverName:
description: ServerName is passed to the server for SNI and is
used in the client to check server ceritificates against. If
ServerName is empty, the upstreamcluster name used to contact
the server is used.
type: string
type: object
dispatchPolicies:
description: DispatchPolicies describes how to dispatch requests to
Expand Down Expand Up @@ -325,6 +331,12 @@ spec:
string
format: byte
type: string
serverNames:
description: ServerNames are used to route requests with different
hostnames for the same upstream cluster.
items:
type: string
type: array
type: object
servers:
description: Servers contains a group of upstream api servers
Expand Down
28 changes: 28 additions & 0 deletions pkg/apis/generated/openapi/openapi_generated.go

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

1 change: 1 addition & 0 deletions pkg/apis/generated/openapi/violations.report
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ API rule violation: list_type_missing,github.com/kubewharf/kubegateway/pkg/apis/
API rule violation: list_type_missing,github.com/kubewharf/kubegateway/pkg/apis/proxy/v1alpha1,SecureServing,CertData
API rule violation: list_type_missing,github.com/kubewharf/kubegateway/pkg/apis/proxy/v1alpha1,SecureServing,ClientCAData
API rule violation: list_type_missing,github.com/kubewharf/kubegateway/pkg/apis/proxy/v1alpha1,SecureServing,KeyData
API rule violation: list_type_missing,github.com/kubewharf/kubegateway/pkg/apis/proxy/v1alpha1,SecureServing,ServerNames
API rule violation: list_type_missing,github.com/kubewharf/kubegateway/pkg/apis/proxy/v1alpha1,UpstreamClusterList,Items
API rule violation: list_type_missing,github.com/kubewharf/kubegateway/pkg/apis/proxy/v1alpha1,UpstreamClusterSpec,DispatchPolicies
API rule violation: list_type_missing,github.com/kubewharf/kubegateway/pkg/apis/proxy/v1alpha1,UpstreamClusterSpec,Servers
Expand Down
399 changes: 257 additions & 142 deletions pkg/apis/proxy/v1alpha1/generated.pb.go

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions pkg/apis/proxy/v1alpha1/generated.proto

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

7 changes: 7 additions & 0 deletions pkg/apis/proxy/v1alpha1/upstreamcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ type SecureServing struct {
// ClientCAData contains PEM-encoded data from a ca file for TLS.
// The serialized form of data is a base64 encoded string
ClientCAData []byte `json:"clientCAData,omitempty" protobuf:"bytes,3,opt,name=clientCAData"`
// ServerNames are used to route requests with different hostnames for the same upstream cluster.
ServerNames []string `json:"serverNames,omitempty" protobuf:"bytes,4,opt,name=serverNames"`
}

type ClientConfig struct {
Expand Down Expand Up @@ -114,6 +116,11 @@ type ClientConfig struct {
// It allows you to set a more precise qps, like 0.01 (qps:1, qpsDivisor:100)
// +optional
QPSDivisor int32 `json:"qpsDivisor,omitempty" protobuf:"varint,8,opt,name=qpsDivisor"`

// ServerName is passed to the server for SNI and is used in the client to check server
// ceritificates against. If ServerName is empty, the upstreamcluster name used to contact the
// server is used.
ServerName string `json:"serverName,omitempty" protobuf:"varint,9,opt,name=serverName"`
}

type FlowControl struct {
Expand Down
15 changes: 15 additions & 0 deletions pkg/clusters/clusterinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ type ClusterInfo struct {
// server Cluster
Cluster string

// serverNames are used to route requests with different hostnames
serverNames sync.Map

// global rate limiter type
globalRateLimiter string

Expand Down Expand Up @@ -234,6 +237,18 @@ func (c *ClusterInfo) LoadVerifyOptions() (x509.VerifyOptions, bool) {
return *cfg.verifyOptions, true
}

func (c *ClusterInfo) LoadServerNames() []string {
var serverNames = []string{c.Cluster}
cfg, ok := c.loadSecureServingConfig()
if ok {
for _, serverName := range cfg.secureServing.ServerNames {
serverNames = append(serverNames, strings.ToLower(serverName))
}
}

return serverNames
}

func (c *ClusterInfo) loadSecureServingConfig() (secureServingConfig, bool) {
empty := secureServingConfig{
secureServing: &proxyv1alpha1.SecureServing{},
Expand Down
27 changes: 22 additions & 5 deletions pkg/clusters/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ type EndpointHealthCheck func(*EndpointInfo) (done bool)

type Manager interface {
Add(*ClusterInfo)
AddWithKey(string, *ClusterInfo)
Get(name string) (*ClusterInfo, bool)
Delete(name string)
DeleteWithStop(name string)
DeleteAll()

ClientProvider
Expand Down Expand Up @@ -59,24 +61,39 @@ func (m *manager) Get(name string) (*ClusterInfo, bool) {
}

func (m *manager) Add(cluster *ClusterInfo) {
m.AddWithKey(cluster.Cluster, cluster)
}

func (m *manager) AddWithKey(key string, cluster *ClusterInfo) {
if cluster == nil {
return
}
cluster.Cluster = strings.ToLower(cluster.Cluster)
klog.V(1).Infof("[cluster manager] new cluster info is added, cluster=%q", cluster.Cluster)
m.clusters.Store(cluster.Cluster, cluster)
key = strings.ToLower(key)
klog.V(1).Infof("[cluster manager] new cluster info is added, cluster=%q [%q]", cluster.Cluster, key)
m.clusters.Store(key, cluster)
}

func (m *manager) Delete(name string) {
m.doDelete(name, false)
}

func (m *manager) DeleteWithStop(name string) {
m.doDelete(name, true)
}

func (m *manager) doDelete(name string, stop bool) {
name = strings.ToLower(name)
v, ok := m.clusters.LoadAndDelete(name)
if !ok {
return
}
// close all requests to this cluster
cluster := v.(*ClusterInfo)
cluster.Stop()
klog.V(1).Infof("[cluster manager] cluster info is deleted, cluster=%q", cluster.Cluster)
if stop {
cluster.Stop()
}

klog.V(1).Infof("[cluster manager] cluster info is deleted, cluster=%q [%q]", cluster.Cluster, name)
}

func (m *manager) DeleteAll() {
Expand Down
7 changes: 6 additions & 1 deletion pkg/clusters/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,14 @@ func buildClusterRESTConfig(cluster *proxyv1alpha1.UpstreamCluster) (*rest.Confi
cfg.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(qps, int(cluster.Spec.ClientConfig.Burst))
}

serverName := cluster.Name
if len(cluster.Spec.ClientConfig.ServerName) > 0 {
serverName = cluster.Spec.ClientConfig.ServerName
}

if httpScheme == "https" {
tlsCfg := rest.TLSClientConfig{
ServerName: cluster.Name,
ServerName: serverName,
KeyData: cluster.Spec.ClientConfig.KeyData,
CertData: cluster.Spec.ClientConfig.CertData,
CAData: cluster.Spec.ClientConfig.CAData,
Expand Down
Loading