Skip to content

Commit

Permalink
expose shutdownmanager image to EnvoyGageway API
Browse files Browse the repository at this point in the history
Signed-off-by: huabing zhao <zhaohuabing@gmail.com>
  • Loading branch information
zhaohuabing committed Apr 24, 2024
1 parent fdb47dd commit d73d1bf
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 36 deletions.
3 changes: 3 additions & 0 deletions api/v1alpha1/envoygateway_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ func (r *EnvoyGatewayProvider) GetEnvoyGatewayKubeProvider() *EnvoyGatewayKubern

r.Kubernetes.RateLimitDeployment.defaultKubernetesDeploymentSpec(DefaultRateLimitImage)

if r.Kubernetes.ShutdownManager == nil {
r.Kubernetes.ShutdownManager = &ShutdownManager{Image: ptr.To(DefaultShutdownManagerImage)}
}
return r.Kubernetes
}

Expand Down
10 changes: 10 additions & 0 deletions api/v1alpha1/envoygateway_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ type EnvoyGatewayKubernetesProvider struct {
// If it's not set up, leader election will be active by default, using Kubernetes' standard settings.
// +optional
LeaderElection *LeaderElection `json:"leaderElection,omitempty"`

// ShutdownManager defines the configuration for the shutdown manager.
// +optional
ShutdownManager *ShutdownManager `json:"shutdownManager,omitempty"`
}

const (
Expand Down Expand Up @@ -536,6 +540,12 @@ type EnvoyGatewayAdminAddress struct {
Host string `json:"host,omitempty"`
}

// ShutdownManager defines the configuration for the shutdown manager.
type ShutdownManager struct {
// Image specifies the ShutdownManager container image to be used, instead of the default image.
Image *string `json:"image,omitempty"`
}

func init() {
SchemeBuilder.Register(&EnvoyGateway{})
}
10 changes: 7 additions & 3 deletions internal/infrastructure/kubernetes/proxy/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ func enablePrometheus(infra *ir.ProxyInfra) bool {
// expectedProxyContainers returns expected proxy containers.
func expectedProxyContainers(infra *ir.ProxyInfra,
containerSpec *egv1a1.KubernetesContainerSpec,
shutdownConfig *egv1a1.ShutdownConfig) ([]corev1.Container, error) {
shutdownConfig *egv1a1.ShutdownConfig,
shutdownManager *egv1a1.ShutdownManager) ([]corev1.Container, error) {
// Define slice to hold container ports
var ports []corev1.ContainerPort

Expand Down Expand Up @@ -229,7 +230,7 @@ func expectedProxyContainers(infra *ir.ProxyInfra,
},
{
Name: "shutdown-manager",
Image: expectedShutdownManagerImage(),
Image: expectedShutdownManagerImage(shutdownManager),
ImagePullPolicy: corev1.PullIfNotPresent,
Command: []string{"envoy-gateway"},
Args: expectedShutdownManagerArgs(shutdownConfig),
Expand Down Expand Up @@ -276,7 +277,10 @@ func expectedProxyContainers(infra *ir.ProxyInfra,
return containers, nil
}

func expectedShutdownManagerImage() string {
func expectedShutdownManagerImage(shutdownManager *egv1a1.ShutdownManager) string {
if shutdownManager != nil && shutdownManager.Image != nil {
return *shutdownManager.Image
}
if v := version.Get().ShutdownManagerVersion; v != "" {
return fmt.Sprintf("%s:%s", strings.Split(egv1a1.DefaultShutdownManagerImage, ":")[0], v)
}
Expand Down
13 changes: 8 additions & 5 deletions internal/infrastructure/kubernetes/proxy/resource_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,15 @@ type ResourceRender struct {

// Namespace is the Namespace used for managed infra.
Namespace string

ShutdownManager *egv1a1.ShutdownManager
}

func NewResourceRender(ns string, infra *ir.ProxyInfra) *ResourceRender {
func NewResourceRender(ns string, infra *ir.ProxyInfra, gateway *egv1a1.EnvoyGateway) *ResourceRender {
return &ResourceRender{
Namespace: ns,
infra: infra,
Namespace: ns,
infra: infra,
ShutdownManager: gateway.GetEnvoyGatewayProvider().GetEnvoyGatewayKubeProvider().ShutdownManager,
}
}

Expand Down Expand Up @@ -199,7 +202,7 @@ func (r *ResourceRender) Deployment() (*appsv1.Deployment, error) {
}

// Get expected bootstrap configurations rendered ProxyContainers
containers, err := expectedProxyContainers(r.infra, deploymentConfig.Container, proxyConfig.Spec.Shutdown)
containers, err := expectedProxyContainers(r.infra, deploymentConfig.Container, proxyConfig.Spec.Shutdown, r.ShutdownManager)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -288,7 +291,7 @@ func (r *ResourceRender) DaemonSet() (*appsv1.DaemonSet, error) {
}

// Get expected bootstrap configurations rendered ProxyContainers
containers, err := expectedProxyContainers(r.infra, daemonSetConfig.Container, proxyConfig.Spec.Shutdown)
containers, err := expectedProxyContainers(r.infra, daemonSetConfig.Container, proxyConfig.Spec.Shutdown, r.ShutdownManager)
if err != nil {
return nil, err
}
Expand Down
41 changes: 24 additions & 17 deletions internal/infrastructure/kubernetes/proxy/resource_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,16 @@ func TestDeployment(t *testing.T) {
require.NoError(t, err)

cases := []struct {
caseName string
infra *ir.Infra
deploy *egv1a1.KubernetesDeploymentSpec
shutdown *egv1a1.ShutdownConfig
proxyLogging map[egv1a1.ProxyLogComponent]egv1a1.LogLevel
bootstrap string
telemetry *egv1a1.ProxyTelemetry
concurrency *int32
extraArgs []string
caseName string
infra *ir.Infra
deploy *egv1a1.KubernetesDeploymentSpec
shutdown *egv1a1.ShutdownConfig
shutdownManager *egv1a1.ShutdownManager
proxyLogging map[egv1a1.ProxyLogComponent]egv1a1.LogLevel
bootstrap string
telemetry *egv1a1.ProxyTelemetry
concurrency *int32
extraArgs []string
}{
{
caseName: "default",
Expand Down Expand Up @@ -173,8 +174,7 @@ func TestDeployment(t *testing.T) {
"env":[
{"name":"env_a","value":"env_a_value"},
{"name":"env_b","value":"env_b_value"}
],
"image":"envoyproxy/gateway-dev:v1.2.3"
]
}]
}
}
Expand All @@ -191,6 +191,9 @@ func TestDeployment(t *testing.T) {
Duration: 15 * time.Second,
},
},
shutdownManager: &egv1a1.ShutdownManager{
Image: ptr.To("privatereop/envoyproxy/gateway-dev:v1.2.3"),
},
},
{
caseName: "bootstrap",
Expand Down Expand Up @@ -544,11 +547,15 @@ func TestDeployment(t *testing.T) {
tc.infra.Proxy.Config.Spec.Shutdown = tc.shutdown
}

if tc.shutdownManager != nil {
cfg.EnvoyGateway.Provider.Kubernetes.ShutdownManager = tc.shutdownManager
}

if len(tc.extraArgs) > 0 {
tc.infra.Proxy.Config.Spec.ExtraArgs = tc.extraArgs
}

r := NewResourceRender(cfg.Namespace, tc.infra.GetProxyInfra())
r := NewResourceRender(cfg.Namespace, tc.infra.GetProxyInfra(), cfg.EnvoyGateway)
dp, err := r.Deployment()
require.NoError(t, err)

Expand Down Expand Up @@ -969,7 +976,7 @@ func TestDaemonSet(t *testing.T) {
tc.infra.Proxy.Config.Spec.ExtraArgs = tc.extraArgs
}

r := NewResourceRender(cfg.Namespace, tc.infra.GetProxyInfra())
r := NewResourceRender(cfg.Namespace, tc.infra.GetProxyInfra(), cfg.EnvoyGateway)
ds, err := r.DaemonSet()
require.NoError(t, err)

Expand Down Expand Up @@ -1084,7 +1091,7 @@ func TestService(t *testing.T) {
provider.EnvoyService = tc.service
}

r := NewResourceRender(cfg.Namespace, tc.infra.GetProxyInfra())
r := NewResourceRender(cfg.Namespace, tc.infra.GetProxyInfra(), cfg.EnvoyGateway)
svc, err := r.Service()
require.NoError(t, err)

Expand Down Expand Up @@ -1127,7 +1134,7 @@ func TestConfigMap(t *testing.T) {

for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
r := NewResourceRender(cfg.Namespace, tc.infra.GetProxyInfra())
r := NewResourceRender(cfg.Namespace, tc.infra.GetProxyInfra(), cfg.EnvoyGateway)
cm, err := r.ConfigMap()
require.NoError(t, err)

Expand Down Expand Up @@ -1171,7 +1178,7 @@ func TestServiceAccount(t *testing.T) {

for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
r := NewResourceRender(cfg.Namespace, tc.infra.GetProxyInfra())
r := NewResourceRender(cfg.Namespace, tc.infra.GetProxyInfra(), cfg.EnvoyGateway)
sa, err := r.ServiceAccount()
require.NoError(t, err)

Expand Down Expand Up @@ -1252,7 +1259,7 @@ func TestHorizontalPodAutoscaler(t *testing.T) {

provider.GetEnvoyProxyKubeProvider()

r := NewResourceRender(cfg.Namespace, tc.infra.GetProxyInfra())
r := NewResourceRender(cfg.Namespace, tc.infra.GetProxyInfra(), cfg.EnvoyGateway)
hpa, err := r.HorizontalPodAutoscaler()
require.NoError(t, err)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ spec:
fieldRef:
apiVersion: v1
fieldPath: metadata.name
image: envoyproxy/gateway-dev:v1.2.3
image: privatereop/envoyproxy/gateway-dev:v1.2.3
imagePullPolicy: IfNotPresent
lifecycle:
preStop:
Expand Down
4 changes: 2 additions & 2 deletions internal/infrastructure/kubernetes/proxy_configmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func TestCreateOrUpdateProxyConfigMap(t *testing.T) {
Build()
}
kube := NewInfra(cli, cfg)
r := proxy.NewResourceRender(kube.Namespace, infra.GetProxyInfra())
r := proxy.NewResourceRender(kube.Namespace, infra.GetProxyInfra(), kube.EnvoyGateway)
err := kube.createOrUpdateConfigMap(context.Background(), r)
require.NoError(t, err)
actual := &corev1.ConfigMap{
Expand Down Expand Up @@ -170,7 +170,7 @@ func TestDeleteConfigProxyMap(t *testing.T) {
infra.Proxy.GetProxyMetadata().Labels[gatewayapi.OwningGatewayNamespaceLabel] = "default"
infra.Proxy.GetProxyMetadata().Labels[gatewayapi.OwningGatewayNameLabel] = infra.Proxy.Name

r := proxy.NewResourceRender(kube.Namespace, infra.GetProxyInfra())
r := proxy.NewResourceRender(kube.Namespace, infra.GetProxyInfra(), kube.EnvoyGateway)
cm := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Namespace: kube.Namespace,
Expand Down
6 changes: 3 additions & 3 deletions internal/infrastructure/kubernetes/proxy_deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestCreateOrUpdateProxyDeployment(t *testing.T) {
infra.Proxy.GetProxyMetadata().Labels[gatewayapi.OwningGatewayNamespaceLabel] = "default"
infra.Proxy.GetProxyMetadata().Labels[gatewayapi.OwningGatewayNameLabel] = infra.Proxy.Name

r := proxy.NewResourceRender(cfg.Namespace, infra.GetProxyInfra())
r := proxy.NewResourceRender(cfg.Namespace, infra.GetProxyInfra(), cfg.EnvoyGateway)
deploy, err := r.Deployment()
require.NoError(t, err)

Expand Down Expand Up @@ -119,7 +119,7 @@ func TestCreateOrUpdateProxyDeployment(t *testing.T) {
}

kube := NewInfra(cli, cfg)
r := proxy.NewResourceRender(kube.Namespace, tc.in.GetProxyInfra())
r := proxy.NewResourceRender(kube.Namespace, tc.in.GetProxyInfra(), cfg.EnvoyGateway)
err := kube.createOrUpdateDeployment(context.Background(), r)
require.NoError(t, err)

Expand Down Expand Up @@ -162,7 +162,7 @@ func TestDeleteProxyDeployment(t *testing.T) {
infra := ir.NewInfra()
infra.Proxy.GetProxyMetadata().Labels[gatewayapi.OwningGatewayNamespaceLabel] = "default"
infra.Proxy.GetProxyMetadata().Labels[gatewayapi.OwningGatewayNameLabel] = infra.Proxy.Name
r := proxy.NewResourceRender(kube.Namespace, infra.GetProxyInfra())
r := proxy.NewResourceRender(kube.Namespace, infra.GetProxyInfra(), kube.EnvoyGateway)

err := kube.createOrUpdateDeployment(context.Background(), r)
require.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions internal/infrastructure/kubernetes/proxy_infra.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (i *Infra) CreateOrUpdateProxyInfra(ctx context.Context, infra *ir.Infra) e
return errors.New("infra proxy ir is nil")
}

r := proxy.NewResourceRender(i.Namespace, infra.GetProxyInfra())
r := proxy.NewResourceRender(i.Namespace, infra.GetProxyInfra(), i.EnvoyGateway)
return i.createOrUpdate(ctx, r)
}

Expand All @@ -33,6 +33,6 @@ func (i *Infra) DeleteProxyInfra(ctx context.Context, infra *ir.Infra) error {
return errors.New("infra ir is nil")
}

r := proxy.NewResourceRender(i.Namespace, infra.GetProxyInfra())
r := proxy.NewResourceRender(i.Namespace, infra.GetProxyInfra(), i.EnvoyGateway)
return i.delete(ctx, r)
}
2 changes: 1 addition & 1 deletion internal/infrastructure/kubernetes/proxy_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestDeleteProxyService(t *testing.T) {

infra.Proxy.GetProxyMetadata().Labels[gatewayapi.OwningGatewayNamespaceLabel] = "default"
infra.Proxy.GetProxyMetadata().Labels[gatewayapi.OwningGatewayNameLabel] = infra.Proxy.Name
r := proxy.NewResourceRender(kube.Namespace, infra.GetProxyInfra())
r := proxy.NewResourceRender(kube.Namespace, infra.GetProxyInfra(), kube.EnvoyGateway)
err := kube.createOrUpdateService(context.Background(), r)
require.NoError(t, err)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func TestCreateOrUpdateProxyServiceAccount(t *testing.T) {

kube := NewInfra(cli, cfg)

r := proxy.NewResourceRender(kube.Namespace, tc.in.GetProxyInfra())
r := proxy.NewResourceRender(kube.Namespace, tc.in.GetProxyInfra(), cfg.EnvoyGateway)
err = kube.createOrUpdateServiceAccount(context.Background(), r)
require.NoError(t, err)

Expand Down Expand Up @@ -221,7 +221,7 @@ func TestDeleteProxyServiceAccount(t *testing.T) {
infra := ir.NewInfra()
infra.Proxy.GetProxyMetadata().Labels[gatewayapi.OwningGatewayNamespaceLabel] = "default"
infra.Proxy.GetProxyMetadata().Labels[gatewayapi.OwningGatewayNameLabel] = infra.Proxy.Name
r := proxy.NewResourceRender(kube.Namespace, infra.GetProxyInfra())
r := proxy.NewResourceRender(kube.Namespace, infra.GetProxyInfra(), kube.EnvoyGateway)

err := kube.createOrUpdateServiceAccount(context.Background(), r)
require.NoError(t, err)
Expand Down

0 comments on commit d73d1bf

Please sign in to comment.