Skip to content

Commit

Permalink
Cleanup: remove kube gateway enabled checks (#10435)
Browse files Browse the repository at this point in the history
  • Loading branch information
jenshu authored Jan 13, 2025
1 parent faeff12 commit fb2ad86
Show file tree
Hide file tree
Showing 14 changed files with 19 additions and 134 deletions.
4 changes: 0 additions & 4 deletions install/helm/gloo/templates/1-gloo-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,6 @@ spec:
valueFrom:
fieldRef:
fieldPath: metadata.namespace
{{- if .Values.kubeGateway.enabled }}
- name: GG_K8S_GW_CONTROLLER
value: "true"
{{- end }}{{/* if .Values.kubeGateway.enabled */}}
{{- if .Values.kubeGateway.portal.enabled }}
- name: GG_PORTAL_PLUGIN
value: "true"
Expand Down
9 changes: 0 additions & 9 deletions install/test/k8sgateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/solo-io/gloo/pkg/utils/kubeutils"
"github.com/solo-io/gloo/projects/gateway2/api/v1alpha1"
"github.com/solo-io/gloo/projects/gateway2/wellknown"
"github.com/solo-io/gloo/projects/gloo/constants"
"github.com/solo-io/gloo/test/gomega/matchers"
glootestutils "github.com/solo-io/gloo/test/testutils"
. "github.com/solo-io/k8s-utils/manifesttestutils"
Expand Down Expand Up @@ -44,14 +43,8 @@ var _ = Describe("Kubernetes Gateway API integration", func() {
})

It("relevant resources are rendered", func() {
// make sure the env variable that enables the controller is set
deployment := getDeployment(testManifest, namespace, kubeutils.GlooDeploymentName)
Expect(deployment.Spec.Template.Spec.Containers).To(HaveLen(1), "should have exactly 1 container")
expectEnvVarExists(deployment.Spec.Template.Spec.Containers[0],
corev1.EnvVar{
Name: constants.GlooGatewayEnableK8sGwControllerEnv,
Value: "true",
})

// make sure the GatewayClass and RBAC resources exist (note, since they are all cluster-scoped, they do not have a namespace)
testManifest.ExpectUnstructured("GatewayClass", "", "gloo-gateway").NotTo(BeNil())
Expand Down Expand Up @@ -491,10 +484,8 @@ var _ = Describe("Kubernetes Gateway API integration", func() {
})

It("relevant resources are not rendered", func() {
// the env variable that enables the controller should not be set
deployment := getDeployment(testManifest, namespace, kubeutils.GlooDeploymentName)
Expect(deployment.Spec.Template.Spec.Containers).To(HaveLen(1), "should have exactly 1 container")
expectEnvVarDoesNotExist(deployment.Spec.Template.Spec.Containers[0], constants.GlooGatewayEnableK8sGwControllerEnv)

// the RBAC resources should not be rendered
testManifest.ExpectUnstructured("GatewayClass", "", "gloo-gateway").To(BeNil())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ type WebhookConfig struct {
alwaysAccept bool // accept all resources
readGatewaysFromAllNamespaces bool
webhookNamespace string
kubeGatewayEnabled bool
}

func NewWebhookConfig(
Expand All @@ -115,7 +114,6 @@ func NewWebhookConfig(
serverCertPath, serverKeyPath string,
alwaysAccept, readGatewaysFromAllNamespaces bool,
webhookNamespace string,
kubeGatewayEnabled bool,
) WebhookConfig {
return WebhookConfig{
ctx: ctx,
Expand All @@ -127,7 +125,6 @@ func NewWebhookConfig(
alwaysAccept: alwaysAccept,
readGatewaysFromAllNamespaces: readGatewaysFromAllNamespaces,
webhookNamespace: webhookNamespace,
kubeGatewayEnabled: kubeGatewayEnabled,
}
}

Expand All @@ -141,7 +138,6 @@ func NewGatewayValidatingWebhook(cfg WebhookConfig) (*http.Server, error) {
alwaysAccept := cfg.alwaysAccept
readGatewaysFromAllNamespaces := cfg.readGatewaysFromAllNamespaces
webhookNamespace := cfg.webhookNamespace
kubeGatewayEnabled := cfg.kubeGatewayEnabled

certProvider, err := NewCertificateProvider(serverCertPath, serverKeyPath, log.New(&debugLogger{ctx: ctx}, "validation-webhook-certificate-watcher", log.LstdFlags), ctx, 10*time.Second)
if err != nil {
Expand All @@ -155,7 +151,6 @@ func NewGatewayValidatingWebhook(cfg WebhookConfig) (*http.Server, error) {
alwaysAccept,
readGatewaysFromAllNamespaces,
webhookNamespace,
kubeGatewayEnabled,
)

mux := http.NewServeMux()
Expand Down Expand Up @@ -184,7 +179,6 @@ type gatewayValidationWebhook struct {
alwaysAccept bool // read only so no races
readGatewaysFromAllNamespaces bool // read only so no races
webhookNamespace string // read only so no races
kubeGatewayEnabled bool // read only so no races
}

type AdmissionReviewWithProxies struct {
Expand All @@ -210,7 +204,6 @@ func NewGatewayValidationHandler(
alwaysAccept bool,
readGatewaysFromAllNamespaces bool,
webhookNamespace string,
kubeGatewayEnabled bool,
) *gatewayValidationWebhook {
return &gatewayValidationWebhook{
ctx: ctx,
Expand All @@ -219,7 +212,6 @@ func NewGatewayValidationHandler(
alwaysAccept: alwaysAccept,
readGatewaysFromAllNamespaces: readGatewaysFromAllNamespaces,
webhookNamespace: webhookNamespace,
kubeGatewayEnabled: kubeGatewayEnabled,
}
}

Expand Down Expand Up @@ -563,8 +555,9 @@ func (wh *gatewayValidationWebhook) validateList(ctx context.Context, rawJson []

func (wh *gatewayValidationWebhook) shouldValidateGvk(gvk schema.GroupVersionKind) bool {
if gvk == gwv1.RouteOptionGVK || gvk == gwv1.VirtualHostOptionGVK {
// only validate RouteOption and VirtualHostOption resources if K8s Gateway is enabled
return wh.kubeGatewayEnabled
// only validate RouteOption and VirtualHostOption resources if K8s Gateway is enabled.
// it is always enabled now, so always return true
return true
}

// no other special considerations at this point, so continue with validation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,10 +492,9 @@ var _ = Describe("ValidatingAdmissionWebhook", func() {
JustBeforeEach(func() {
mv = &mockValidator{}
wh = &gatewayValidationWebhook{
webhookNamespace: "namespace",
ctx: context.TODO(),
validator: mv,
kubeGatewayEnabled: true,
webhookNamespace: "namespace",
ctx: context.TODO(),
validator: mv,
}
srv = httptest.NewServer(wh)
})
Expand Down
12 changes: 1 addition & 11 deletions projects/gloo/cli/pkg/cmd/check/kube_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,13 @@ func CheckKubeGatewayResources(ctx context.Context, printer printers.P, opts *op
return multiErr.ErrorOrNil()
}

// check if Kubernetes Gateway integration is enabled by checking if the Gateway API CRDs are installed and
// whether the GG_K8S_GW_CONTROLLER env var is true in the gloo deployment.
// check if Kubernetes Gateway integration is enabled by checking if the Gateway API CRDs are installed
func isKubeGatewayEnabled(ctx context.Context, opts *options.Options) (bool, error) {
cfg, err := kubeutils.GetRestConfigWithKubeContext(opts.Top.KubeContext)
if err != nil {
return false, err
}

gatewayEnabled, err := kubegatewayutils.DetectKubeGatewayEnabled(ctx, opts)
if err != nil {
return false, eris.Wrapf(err, "unable to determine if Kubernetes Gateway integration is enabled")
}

if !gatewayEnabled {
return false, nil
}

hasCRDs, err := kubegatewayutils.DetectKubeGatewayCrds(cfg)
if err != nil {
return false, eris.Wrapf(err, "unable to determine if Kubernetes Gateway CRDs are applied")
Expand Down
53 changes: 0 additions & 53 deletions projects/gloo/cli/pkg/kubegatewayutils/detect.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
package kubegatewayutils

import (
"context"
"strconv"

"github.com/rotisserie/eris"
"github.com/solo-io/gloo/projects/gateway2/wellknown"
"github.com/solo-io/gloo/projects/gloo/cli/pkg/cmd/options"
cliconstants "github.com/solo-io/gloo/projects/gloo/cli/pkg/constants"
"github.com/solo-io/gloo/projects/gloo/cli/pkg/helpers"
"github.com/solo-io/gloo/projects/gloo/constants"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/discovery"
"k8s.io/client-go/rest"
)
Expand All @@ -38,46 +28,3 @@ func DetectKubeGatewayCrds(cfg *rest.Config) (bool, error) {

return false, nil
}

// Returns true if the GG_K8S_GW_CONTROLLER env var is true in the gloo deployment.
// Note: This is tied up with the GG implementation and will need to be updated if it changes
func DetectKubeGatewayEnabled(ctx context.Context, opts *options.Options) (bool, error) {
glooDeploymentName, err := helpers.GetGlooDeploymentName(opts.Top.Ctx, opts.Metadata.GetNamespace())
if err != nil {
return false, err
}

// check if Kubernetes Gateway integration is enabled by checking if the controller env variable is set in the
// gloo deployment
client, err := helpers.GetKubernetesClient(opts.Top.KubeContext)
if err != nil {
return false, eris.Wrapf(err, "could not get kubernetes client")
}

glooDeployment, err := client.AppsV1().Deployments(opts.Metadata.GetNamespace()).Get(ctx, glooDeploymentName, metav1.GetOptions{})
if err != nil {
return false, eris.Wrapf(err, "could not get gloo deployment")
}

var glooContainer *corev1.Container
for _, container := range glooDeployment.Spec.Template.Spec.Containers {
if container.Name == cliconstants.GlooContainerName {
glooContainer = &container
break
}
}
if glooContainer == nil {
return false, eris.New("could not find gloo container in gloo deployment")
}

for _, envVar := range glooContainer.Env {
if envVar.Name == constants.GlooGatewayEnableK8sGwControllerEnv {
val, err := strconv.ParseBool(envVar.Value)
if err != nil {
return false, eris.Wrapf(err, "could not parse value of %s env var in gloo deployment", constants.GlooGatewayEnableK8sGwControllerEnv)
}
return val, nil
}
}
return false, nil
}
5 changes: 0 additions & 5 deletions projects/gloo/constants/gloo_gateway.go

This file was deleted.

3 changes: 1 addition & 2 deletions projects/gloo/pkg/bootstrap/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ type IstioValues struct {
}

type GlooGateway struct {
EnableK8sGatewayController bool
IstioValues IstioValues
IstioValues IstioValues
}

type Consul struct {
Expand Down
11 changes: 3 additions & 8 deletions projects/gloo/pkg/servers/iosnapshot/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ type History interface {

// HistoryFactoryParameters are the inputs used to create a History object
type HistoryFactoryParameters struct {
Settings *gloov1.Settings
Cache cache.SnapshotCache
EnableK8sGatewayIntegration bool
Settings *gloov1.Settings
Cache cache.SnapshotCache
}

// HistoryFactory is a function that produces a History object
Expand All @@ -72,11 +71,7 @@ func GetHistoryFactory() HistoryFactory {
}
}

// By default, only return the GVKs for using Gloo Gateway, with purely the Edge Gateway APIs
var gvks = EdgeOnlyInputSnapshotGVKs
if params.EnableK8sGatewayIntegration {
gvks = CompleteInputSnapshotGVKs
}
gvks := CompleteInputSnapshotGVKs

return NewHistory(params.Cache, params.Settings, kubeClient, gvks)
}
Expand Down
3 changes: 1 addition & 2 deletions projects/gloo/pkg/servers/iosnapshot/history_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ var _ = Describe("History", func() {
Namespace: defaults.GlooSystem,
},
},
Cache: &xds.MockXdsCache{},
EnableK8sGatewayIntegration: true,
Cache: &xds.MockXdsCache{},
}
})

Expand Down
11 changes: 3 additions & 8 deletions projects/gloo/pkg/syncer/setup/setup_syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -898,9 +898,8 @@ func RunGlooWithExtensions(opts bootstrap.Opts, extensions Extensions) error {
// snapshotHistory is a utility for managing the state of the input/output snapshots that the Control Plane
// consumes and produces. This object is then used by our Admin Server, to provide this data on demand
snapshotHistory := extensions.SnapshotHistoryFactory(iosnapshot.HistoryFactoryParameters{
Settings: opts.Settings,
Cache: opts.ControlPlane.SnapshotCache,
EnableK8sGatewayIntegration: opts.GlooGateway.EnableK8sGatewayController,
Settings: opts.Settings,
Cache: opts.ControlPlane.SnapshotCache,
})

startFuncs["admin-server"] = AdminServerStartFunc(snapshotHistory, opts.KrtDebugger)
Expand Down Expand Up @@ -1012,7 +1011,6 @@ func RunGlooWithExtensions(opts bootstrap.Opts, extensions Extensions) error {
gwOpts.Validation.AlwaysAcceptResources,
gwOpts.ReadGatewaysFromAllNamespaces,
gwOpts.GlooNamespace,
opts.GlooGateway.EnableK8sGatewayController, // controls validation of KubeGateway policies (e.g. RouteOption, VirtualHostOption)
),
)
if err != nil {
Expand Down Expand Up @@ -1350,10 +1348,7 @@ func constructOpts(ctx context.Context, setup *bootstrap.SetupOpts, params const

func constructGlooGatewayBootstrapOpts(settings *v1.Settings) bootstrap.GlooGateway {
return bootstrap.GlooGateway{
// TODO: This value should be inherited at installation time, to determine if the k8s controller is enabled
// In the interim, we use an env variable to control the value
EnableK8sGatewayController: envutils.IsEnvTruthy(constants.GlooGatewayEnableK8sGwControllerEnv),
IstioValues: constructIstioBootstrapOpts(settings),
IstioValues: constructIstioBootstrapOpts(settings),
}
}

Expand Down
7 changes: 1 addition & 6 deletions projects/gloo/pkg/translator/clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import (
"github.com/golang/protobuf/ptypes/wrappers"
"github.com/rotisserie/eris"
"github.com/solo-io/gloo/pkg/utils/api_conversion"
"github.com/solo-io/gloo/pkg/utils/envutils"
"github.com/solo-io/gloo/projects/gloo/constants"
v1 "github.com/solo-io/gloo/projects/gloo/pkg/api/v1"
v1_options "github.com/solo-io/gloo/projects/gloo/pkg/api/v1/options"
"github.com/solo-io/gloo/projects/gloo/pkg/api/v1/ssl"
Expand Down Expand Up @@ -143,6 +141,7 @@ func (t *translatorInstance) initializeCluster(
circuitBreakers := t.settings.GetGloo().GetCircuitBreakers()
out := &envoy_config_cluster_v3.Cluster{
Name: UpstreamToClusterName(upstream.GetMetadata().Ref()),
AltStatName: UpstreamToClusterStatsName(upstream),
Metadata: new(envoy_config_core_v3.Metadata),
CircuitBreakers: getCircuitBreakers(upstream.GetCircuitBreakers(), circuitBreakers),
LbSubsetConfig: createLbConfig(upstream),
Expand All @@ -158,10 +157,6 @@ func (t *translatorInstance) initializeCluster(
DnsRefreshRate: dnsRefreshRate,
PreconnectPolicy: preconnect,
}
// for kube gateway, use new stats name format
if envutils.IsEnvTruthy(constants.GlooGatewayEnableK8sGwControllerEnv) {
out.AltStatName = UpstreamToClusterStatsName(upstream)
}

if sslConfig := upstream.GetSslConfig(); sslConfig != nil {
applyDefaultsToUpstreamSslConfig(sslConfig, t.settings.GetUpstreamOptions())
Expand Down
9 changes: 0 additions & 9 deletions test/consulvaulte2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"os"
"testing"

"github.com/solo-io/gloo/projects/gloo/constants"

"github.com/solo-io/gloo/test/services/envoy"

"github.com/solo-io/gloo/test/ginkgo/labels"
Expand Down Expand Up @@ -49,17 +47,10 @@ var _ = BeforeSuite(func() {
Expect(err).NotTo(HaveOccurred())
vaultFactory, err = services.NewVaultFactory()
Expect(err).NotTo(HaveOccurred())

// The consulvaulte2e test suite is not run against a k8s cluster, so we must disable the features that require a k8s cluster
err = os.Setenv(constants.GlooGatewayEnableK8sGwControllerEnv, "false")
Expect(err).NotTo(HaveOccurred())
})

var _ = AfterSuite(func() {
envoyFactory.Clean()
_ = consulFactory.Clean()
_ = vaultFactory.Clean()

err := os.Unsetenv(constants.GlooGatewayEnableK8sGwControllerEnv)
Expect(err).NotTo(HaveOccurred())
})
6 changes: 3 additions & 3 deletions test/services/gloo.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,10 +378,10 @@ func constructTestOpts(ctx context.Context, runOptions *RunOptions, settings *gl
GatewayControllerEnabled: settings.GetGateway().GetEnableGatewayController().GetValue(),
ValidationOpts: validationOpts,
Identity: singlereplica.Identity(),
GlooGateway: bootstrap.GlooGateway{
GlooGateway: bootstrap.GlooGateway{
// The K8s Gateway Integration depends on a functioning k8s cluster
// These tests are designed to be run in-memory, without a true cluster, so we disable the relevant controller
EnableK8sGatewayController: false,
// These tests are designed to be run in-memory, without a true cluster
// TODO: delete any tests that cannot run when k8s gw api is used
},
}
}
Expand Down

0 comments on commit fb2ad86

Please sign in to comment.