Skip to content

Commit

Permalink
Merge branch 'release/v1.1' into feature/new-config-options
Browse files Browse the repository at this point in the history
  • Loading branch information
reaver-flomesh committed Oct 27, 2023
2 parents a9258c8 + fed84de commit 67397f8
Show file tree
Hide file tree
Showing 11 changed files with 712 additions and 62 deletions.
15 changes: 15 additions & 0 deletions charts/fsm/components/scripts/gateways/extension/agent-service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
((
) => pipy()

.pipeline()
.handleMessageStart(
msg => (
msg?.head?.headers?.['hy-agent-rsn'] && (
msg.head.headers['orig-host'] = msg.head.headers.host,
msg.head.headers.host = msg.head.headers['hy-agent-rsn']
)
)
)
.chain()

)()
1 change: 1 addition & 0 deletions charts/fsm/templates/fsm-consul-connector-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ spec:
"-mesh-name", "{{.Values.fsm.meshName}}",
"-trust-domain", "{{.Values.fsm.trustDomain}}",
"-derive-namespace={{.Values.fsm.cloudConnector.consul.deriveNamespace}}",
"-with-gateway-api={{.Values.fsm.fsmGateway.enabled}}",
"-http-addr={{.Values.fsm.cloudConnector.consul.httpAddr}}",
"-passing-only={{.Values.fsm.cloudConnector.consul.passingOnly}}",
"-filter-tag={{.Values.fsm.cloudConnector.consul.filterTag}}",
Expand Down
1 change: 1 addition & 0 deletions charts/fsm/templates/fsm-eureka-connector-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ spec:
"-mesh-name", "{{.Values.fsm.meshName}}",
"-trust-domain", "{{.Values.fsm.trustDomain}}",
"-derive-namespace={{.Values.fsm.cloudConnector.eureka.deriveNamespace}}",
"-with-gateway-api={{.Values.fsm.fsmGateway.enabled}}",
"-http-addr={{.Values.fsm.cloudConnector.eureka.httpAddr}}",
"-passing-only={{.Values.fsm.cloudConnector.eureka.passingOnly}}",
"-filter-tag={{.Values.fsm.cloudConnector.eureka.filterTag}}",
Expand Down
4 changes: 2 additions & 2 deletions charts/fsm/templates/fsm-rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ rules:
- apiGroups: [""]
resources: ["nodes"]
verbs: ["get", "list", "watch"]
{{- if semverCompare ">=1.21-0" .Capabilities.KubeVersion.GitVersion }}
{{- if (semverCompare ">=1.21-0" .Capabilities.KubeVersion.GitVersion) }}
- apiGroups: ["discovery.k8s.io"]
resources: ["endpointslices"]
verbs: ["get", "list", "watch", "update", "patch"]
verbs: ["get", "list", "watch", "create", "update", "patch"]
{{- end }}

# Port forwarding is needed for the FSM pod to be able to connect
Expand Down
9 changes: 7 additions & 2 deletions cmd/fsm-connector/consul/fsm-consul-connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
gwapi "sigs.k8s.io/gateway-api/pkg/client/clientset/versioned"

"github.com/hashicorp/consul/command/flags"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -48,6 +49,7 @@ var (
prefixTag string
suffixTag string
deriveNamespace string
withGatewayAPI bool

scheme = runtime.NewScheme()
)
Expand All @@ -72,6 +74,7 @@ func init() {
cliFlags.StringVar(&prefixTag, "prefix-tag", "", "prefix tag")
cliFlags.StringVar(&suffixTag, "suffix-tag", "", "suffix tag")
cliFlags.BoolVar(&passingOnly, "passing-only", true, "passing only")
cliFlags.BoolVar(&withGatewayAPI, "with-gateway-api", false, "with gateway api")
cliFlags.StringVar(&deriveNamespace, "derive-namespace", "", "derive namespace")
flags.Merge(cliFlags, httpFlags.ClientFlags())

Expand All @@ -93,9 +96,11 @@ func main() {
log.Fatal().Err(err).Msgf("Error creating kube config (kubeconfig=%s)", kubeConfigFile)
}
kubeClient := kubernetes.NewForConfigOrDie(kubeConfig)
gatewayClient := gwapi.NewForConfigOrDie(kubeConfig)

k8s.SetTrustDomain(trustDomain)

connector.EnabledGatewayAPI(withGatewayAPI)
connector.SetSyncCloudNamespace(deriveNamespace)

// Initialize the generic Kubernetes event recorder and associate it with the fsm-consul-connector pod resource
Expand Down Expand Up @@ -124,7 +129,7 @@ func main() {
events.GenericEventRecorder().FatalEvent(err, events.InitializationError, "Error creating consul client")
}

sink := connector.NewSink(ctx, kubeClient)
sink := connector.NewSink(ctx, kubeClient, gatewayClient, fsmNamespace)
source := &consulConnector.Source{
ConsulClient: consulClient,
Domain: trustDomain,
Expand Down Expand Up @@ -161,7 +166,7 @@ func main() {
}

// Start the global log level watcher that updates the log level dynamically
go k8s.WatchAndUpdateLogLevel(msgBroker, stop)
go connector.WatchMeshConfigUpdated(msgBroker, stop)

<-stop
log.Info().Msgf("Stopping fsm-consul-connector %s; %s; %s", version.Version, version.GitCommit, version.BuildDate)
Expand Down
9 changes: 7 additions & 2 deletions cmd/fsm-connector/eureka/fsm-eureka-connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
gwapi "sigs.k8s.io/gateway-api/pkg/client/clientset/versioned"

"github.com/hudl/fargo"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -49,6 +50,7 @@ var (
prefixTag string
suffixTag string
deriveNamespace string
withGatewayAPI bool

scheme = runtime.NewScheme()
)
Expand All @@ -73,6 +75,7 @@ func init() {
cliFlags.StringVar(&prefixTag, "prefix-tag", "", "prefix tag")
cliFlags.StringVar(&suffixTag, "suffix-tag", "", "suffix tag")
cliFlags.BoolVar(&passingOnly, "passing-only", true, "passing only")
cliFlags.BoolVar(&withGatewayAPI, "with-gateway-api", false, "with gateway api")
cliFlags.StringVar(&deriveNamespace, "derive-namespace", "", "derive namespace")

_ = clientgoscheme.AddToScheme(scheme)
Expand All @@ -93,9 +96,11 @@ func main() {
log.Fatal().Err(err).Msgf("Error creating kube config (kubeconfig=%s)", kubeConfigFile)
}
kubeClient := kubernetes.NewForConfigOrDie(kubeConfig)
gatewayClient := gwapi.NewForConfigOrDie(kubeConfig)

k8s.SetTrustDomain(trustDomain)

connector.EnabledGatewayAPI(withGatewayAPI)
connector.SetSyncCloudNamespace(deriveNamespace)

// Initialize the generic Kubernetes event recorder and associate it with the fsm-eureka-connector pod resource
Expand All @@ -121,7 +126,7 @@ func main() {

eurekaClient := fargo.NewConn(httpAddr)

sink := connector.NewSink(ctx, kubeClient)
sink := connector.NewSink(ctx, kubeClient, gatewayClient, fsmNamespace)
source := &eurekaConnector.Source{
EurekaClient: &eurekaClient,
Domain: trustDomain,
Expand Down Expand Up @@ -158,7 +163,7 @@ func main() {
}

// Start the global log level watcher that updates the log level dynamically
go k8s.WatchAndUpdateLogLevel(msgBroker, stop)
go connector.WatchMeshConfigUpdated(msgBroker, stop)

<-stop
log.Info().Msgf("Stopping fsm-eureka-connector %s; %s; %s", version.Version, version.GitCommit, version.BuildDate)
Expand Down
4 changes: 2 additions & 2 deletions pkg/connector/consul/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (s *Source) Run(ctx context.Context) {
services[connector.MicroSvcName(s.Prefix+name)] = connector.MicroSvcDomainName(fmt.Sprintf("%s.service.%s", name, s.Domain))
}
}
log.Info().Msgf("received services from Consul, count:%d", len(services))
log.Trace().Msgf("received services from Consul, count:%d", len(services))
s.Sink.SetServices(services)
}
}
Expand All @@ -102,7 +102,7 @@ func (s *Source) Aggregate(svcName connector.MicroSvcName, svcDomainName connect
log.Err(err).Msgf("can't retrieve consul service, name:%s", string(svcName))
return nil, connector.ConsulDiscoveryService
}
log.Info().Msgf("PassingOnly:%v FilterTag:%v len(serviceEntries):%d", s.PassingOnly, s.FilterTag, len(serviceEntries))
log.Trace().Msgf("PassingOnly:[%v] FilterTag:[%v] len(serviceEntries):[%d]", s.PassingOnly, s.FilterTag, len(serviceEntries))
if len(serviceEntries) == 0 {
return nil, connector.ConsulDiscoveryService
}
Expand Down
Loading

0 comments on commit 67397f8

Please sign in to comment.