Skip to content

Commit

Permalink
merge & fix conflict
Browse files Browse the repository at this point in the history
Signed-off-by: Gang Liu <[email protected]>
  • Loading branch information
izturn committed Nov 2, 2022
2 parents 021ccd1 + fac2c32 commit a11945d
Show file tree
Hide file tree
Showing 16 changed files with 155 additions and 24 deletions.
33 changes: 19 additions & 14 deletions apis/projectcontour/v1alpha1/contourdeployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
package v1alpha1

import (
"fmt"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand All @@ -24,22 +22,23 @@ import (
type LogLevel string

const (
// InfoLog sets the log level for Contour to `info`.
InfoLog LogLevel = "info"

// DebugLog sets the log level for Contour to `debug`.
// TraceLog sets the log level for Envoy to `trace`.
TraceLog LogLevel = "trace"
// DebugLog sets the log level for Contour/Envoy to `debug`.
DebugLog LogLevel = "debug"
// InfoLog sets the log level for Contour/Envoy to `info`.
InfoLog LogLevel = "info"
// WarnLog sets the log level for Envoy to `warn`.
WarnLog LogLevel = "warn"
// ErrorLog sets the log level for Envoy to `error`.
ErrorLog LogLevel = "error"
// CriticalLog sets the log level for Envoy to `critical`.
CriticalLog LogLevel = "critical"
// OffLog disable logging for Envoy.
OffLog LogLevel = "off"
)

func (l LogLevel) Validate() error {
switch l {
case InfoLog, DebugLog:
return nil
default:
return fmt.Errorf("invalid log level %q", l)
}
}

// ContourDeploymentSpec specifies options for how a Contour
// instance should be provisioned.
type ContourDeploymentSpec struct {
Expand Down Expand Up @@ -151,6 +150,12 @@ type EnvoySettings struct {
// More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
// +optional
Resources corev1.ResourceRequirements `json:"resources,omitempty"`

// LogLevel sets the log level for Envoy.
// Allowed values are "trace", "debug", "info", "warn", "error", "critical", "off".
//
// +optional
LogLevel LogLevel `json:"logLevel,omitempty"`
}

// WorkloadType is the type of Kubernetes workload to use for a component.
Expand Down
1 change: 1 addition & 0 deletions changelogs/unreleased/4801-izturn-small.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add Envoy log level configurability to ContourDeployment resource.
4 changes: 4 additions & 0 deletions examples/contour/01-crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2563,6 +2563,10 @@ spec:
- name
type: object
type: array
logLevel:
description: LogLevel sets the log level for Envoy. Allowed values
are "trace", "debug", "info", "warn", "error", "critical", "off".
type: string
networkPublishing:
description: NetworkPublishing defines how to expose Envoy to
a network.
Expand Down
4 changes: 4 additions & 0 deletions examples/render/contour-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2772,6 +2772,10 @@ spec:
- name
type: object
type: array
logLevel:
description: LogLevel sets the log level for Envoy. Allowed values
are "trace", "debug", "info", "warn", "error", "critical", "off".
type: string
networkPublishing:
description: NetworkPublishing defines how to expose Envoy to
a network.
Expand Down
4 changes: 4 additions & 0 deletions examples/render/contour-gateway-provisioner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2577,6 +2577,10 @@ spec:
- name
type: object
type: array
logLevel:
description: LogLevel sets the log level for Envoy. Allowed values
are "trace", "debug", "info", "warn", "error", "critical", "off".
type: string
networkPublishing:
description: NetworkPublishing defines how to expose Envoy to
a network.
Expand Down
4 changes: 4 additions & 0 deletions examples/render/contour-gateway.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2778,6 +2778,10 @@ spec:
- name
type: object
type: array
logLevel:
description: LogLevel sets the log level for Envoy. Allowed values
are "trace", "debug", "info", "warn", "error", "critical", "off".
type: string
networkPublishing:
description: NetworkPublishing defines how to expose Envoy to
a network.
Expand Down
4 changes: 4 additions & 0 deletions examples/render/contour.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2772,6 +2772,10 @@ spec:
- name
type: object
type: array
logLevel:
description: LogLevel sets the log level for Envoy. Allowed values
are "trace", "debug", "info", "warn", "error", "critical", "off".
type: string
networkPublishing:
description: NetworkPublishing defines how to expose Envoy to
a network.
Expand Down
7 changes: 6 additions & 1 deletion internal/provisioner/controller/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func (r *gatewayReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct

contourModel.Spec.ContourResources = gatewayClassParams.Spec.Contour.Resources

contourModel.Spec.LogLevel = gatewayClassParams.Spec.Contour.LogLevel
contourModel.Spec.ContourLogLevel = gatewayClassParams.Spec.Contour.LogLevel

contourModel.Spec.KubernetesLogLevel = gatewayClassParams.Spec.Contour.KubernetesLogLevel
}
Expand Down Expand Up @@ -314,6 +314,11 @@ func (r *gatewayReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
}

contourModel.Spec.EnvoyResources = gatewayClassParams.Spec.Envoy.Resources

if gatewayClassParams.Spec.Envoy.LogLevel != "" {
contourModel.Spec.EnvoyLogLevel = gatewayClassParams.Spec.Envoy.LogLevel
}

}
}

Expand Down
11 changes: 11 additions & 0 deletions internal/provisioner/controller/gatewayclass.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"fmt"
"strings"

"github.com/projectcontour/contour/apis/projectcontour/v1alpha1"
contour_api_v1alpha1 "github.com/projectcontour/contour/apis/projectcontour/v1alpha1"

"github.com/go-logr/logr"
Expand Down Expand Up @@ -204,6 +205,16 @@ func (r *gatewayClassReconciler) Reconcile(ctx context.Context, req ctrl.Request
}
}
}

switch params.Spec.Envoy.LogLevel {
// valid values, nothing to do.
case "", v1alpha1.TraceLog, v1alpha1.DebugLog, v1alpha1.InfoLog, v1alpha1.WarnLog, v1alpha1.ErrorLog, v1alpha1.CriticalLog, v1alpha1.OffLog:
// invalid value, set message.
default:
msg := fmt.Sprintf("invalid ContourDeployment spec.envoy.logLevel %q, must be trace, debug, info, warn, error, critical or off",
params.Spec.Envoy.LogLevel)
invalidParamsMessages = append(invalidParamsMessages, msg)
}
}

if len(invalidParamsMessages) > 0 {
Expand Down
32 changes: 32 additions & 0 deletions internal/provisioner/controller/gatewayclass_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,38 @@ func TestGatewayClassReconcile(t *testing.T) {
Reason: string(gatewayv1beta1.GatewayClassReasonInvalidParameters),
},
},
"gatewayclass controlled by us with a valid parametersRef but invalid parameter values for LogLevel gets Accepted: false condition": {
gatewayClass: &gatewayv1beta1.GatewayClass{
ObjectMeta: metav1.ObjectMeta{
Name: "gatewayclass-1",
},
Spec: gatewayv1beta1.GatewayClassSpec{
ControllerName: "projectcontour.io/gateway-controller",
ParametersRef: &gatewayv1beta1.ParametersReference{
Group: "projectcontour.io",
Kind: "ContourDeployment",
Name: "gatewayclass-params",
Namespace: gatewayapi.NamespacePtr("projectcontour"),
},
},
},
params: &contourv1alpha1.ContourDeployment{
ObjectMeta: metav1.ObjectMeta{
Namespace: "projectcontour",
Name: "gatewayclass-params",
},
Spec: contourv1alpha1.ContourDeploymentSpec{
Envoy: &contourv1alpha1.EnvoySettings{
LogLevel: "invalidLevel",
},
},
},
wantCondition: &metav1.Condition{
Type: string(gatewayv1beta1.GatewayClassConditionStatusAccepted),
Status: metav1.ConditionFalse,
Reason: string(gatewayv1beta1.GatewayClassReasonInvalidParameters),
},
},
"gatewayclass controlled by us with a valid parametersRef but invalid parameter values for ExternalTrafficPolicy gets Accepted: false condition": {
gatewayClass: &gatewayv1beta1.GatewayClass{
ObjectMeta: metav1.ObjectMeta{
Expand Down
9 changes: 7 additions & 2 deletions internal/provisioner/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func Default(namespace, name string) *Contour {
ContourReplicas: 2,
EnvoyWorkloadType: WorkloadTypeDaemonSet,
EnvoyReplicas: 2, // ignored if not provisioning Envoy as a deployment.
EnvoyLogLevel: contourv1alpha1.InfoLog,
NetworkPublishing: NetworkPublishing{
Envoy: EnvoyNetworkPublishing{
Type: LoadBalancerServicePublishingType,
Expand Down Expand Up @@ -144,9 +145,9 @@ type ContourSpec struct {
// https://projectcontour.io/docs/main/config/annotations/#ingress-class
IngressClassName *string

// LogLevel sets the log level for Contour
// ContourLogLevel sets the log level for Contour
// Allowed values are "info", "debug".
LogLevel contourv1alpha1.LogLevel
ContourLogLevel contourv1alpha1.LogLevel

// NodePlacement enables scheduling of Contour and Envoy pods onto specific nodes.
//
Expand Down Expand Up @@ -187,6 +188,10 @@ type ContourSpec struct {

// Compute Resources required by contour container.
ContourResources corev1.ResourceRequirements

// EnvoyLogLevel sets the log level for Envoy
// Allowed values are "trace", "debug", "info", "warn", "error", "critical", "off".
EnvoyLogLevel contourv1alpha1.LogLevel
}

// WorkloadType is the type of Kubernetes workload to use for a component.
Expand Down
2 changes: 1 addition & 1 deletion internal/provisioner/objects/dataplane/dataplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func desiredContainers(contour *model.Contour, contourImage, envoyImage string)
filepath.Join("/", envoyCfgVolMntDir, envoyCfgFileName),
fmt.Sprintf("--service-cluster $(%s)", envoyNsEnvVar),
fmt.Sprintf("--service-node $(%s)", envoyPodEnvVar),
"--log-level info",
fmt.Sprintf("--log-level %s", contour.Spec.EnvoyLogLevel),
},
Env: []corev1.EnvVar{
{
Expand Down
20 changes: 20 additions & 0 deletions internal/provisioner/objects/dataplane/dataplane_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"fmt"
"testing"

"github.com/projectcontour/contour/apis/projectcontour/v1alpha1"
"github.com/projectcontour/contour/internal/provisioner/model"

appsv1 "k8s.io/api/apps/v1"
Expand Down Expand Up @@ -200,6 +201,17 @@ func checkDaemonSecurityContext(t *testing.T, ds *appsv1.DaemonSet) {
t.Errorf("deployment has unexpected SecurityContext %v", expected)
}

func checkContainerHasArg(t *testing.T, container *corev1.Container, arg string) {
t.Helper()

for _, a := range container.Args {
if a == arg {
return
}
}
t.Errorf("container is missing argument %q", arg)
}

func TestDesiredDaemonSet(t *testing.T) {
name := "ds-test"
cntr := model.Default(fmt.Sprintf("%s-ns", name), name)
Expand All @@ -222,6 +234,7 @@ func TestDesiredDaemonSet(t *testing.T) {

testContourImage := "ghcr.io/projectcontour/contour:test"
testEnvoyImage := "docker.io/envoyproxy/envoy:test"
testLogLevelArg := "--log-level debug"

resQutoa := corev1.ResourceRequirements{
Limits: corev1.ResourceList{
Expand All @@ -234,9 +247,15 @@ func TestDesiredDaemonSet(t *testing.T) {
},
}
cntr.Spec.EnvoyResources = resQutoa

// Change the Envoy log level to test --log-level debug.
cntr.Spec.EnvoyLogLevel = v1alpha1.DebugLog

ds := DesiredDaemonSet(cntr, testContourImage, testEnvoyImage)
container := checkDaemonSetHasContainer(t, ds, EnvoyContainerName, true)
checkContainerHasArg(t, container, testLogLevelArg)
checkContainerHasImage(t, container, testEnvoyImage)

container = checkDaemonSetHasContainer(t, ds, ShutdownContainerName, true)
checkContainerHasImage(t, container, testContourImage)
container = checkDaemonSetHasContainer(t, ds, envoyInitContainerName, true)
Expand All @@ -255,6 +274,7 @@ func TestDesiredDaemonSet(t *testing.T) {
checkDaemonSetHasPodAnnotations(t, ds, envoyPodAnnotations(cntr))

checkDaemonSetHasResourceRequirements(t, ds, resQutoa)

}

func TestNodePlacementDaemonSet(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion internal/provisioner/objects/deployment/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func DesiredDeployment(contour *model.Contour, image string) *appsv1.Deployment
fmt.Sprintf("--kubernetes-debug=%d", contour.Spec.KubernetesLogLevel),
}

if contour.Spec.LogLevel == v1alpha1.DebugLog {
if contour.Spec.ContourLogLevel == v1alpha1.DebugLog {
args = append(args, "--debug")
}

Expand Down
2 changes: 1 addition & 1 deletion internal/provisioner/objects/deployment/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func TestDesiredDeployment(t *testing.T) {
cntr.Spec.KubernetesLogLevel = 7

// Change the Contour log level to test --debug.
cntr.Spec.LogLevel = v1alpha1.DebugLog
cntr.Spec.ContourLogLevel = v1alpha1.DebugLog

cntr.Spec.ResourceLabels = map[string]string{
"key": "value",
Expand Down
40 changes: 36 additions & 4 deletions site/content/docs/main/config/api-reference.html
Original file line number Diff line number Diff line change
Expand Up @@ -6074,6 +6074,22 @@ <h3 id="projectcontour.io/v1alpha1.EnvoySettings">EnvoySettings
More info: <a href="https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/">https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/</a></p>
</td>
</tr>
<tr>
<td style="white-space:nowrap">
<code>logLevel</code>
<br>
<em>
<a href="#projectcontour.io/v1alpha1.LogLevel">
LogLevel
</a>
</em>
</td>
<td>
<em>(Optional)</em>
<p>LogLevel sets the log level for Envoy.
Allowed values are &ldquo;trace&rdquo;, &ldquo;debug&rdquo;, &ldquo;info&rdquo;, &ldquo;warn&rdquo;, &ldquo;error&rdquo;, &ldquo;critical&rdquo;, &ldquo;off&rdquo;.</p>
</td>
</tr>
</tbody>
</table>
<h3 id="projectcontour.io/v1alpha1.EnvoyTLS">EnvoyTLS
Expand Down Expand Up @@ -6673,7 +6689,8 @@ <h3 id="projectcontour.io/v1alpha1.LogLevel">LogLevel
(<code>string</code> alias)</p></h3>
<p>
(<em>Appears on:</em>
<a href="#projectcontour.io/v1alpha1.ContourSettings">ContourSettings</a>)
<a href="#projectcontour.io/v1alpha1.ContourSettings">ContourSettings</a>,
<a href="#projectcontour.io/v1alpha1.EnvoySettings">EnvoySettings</a>)
</p>
<p>
<p>LogLevel is the logging levels available.</p>
Expand All @@ -6685,11 +6702,26 @@ <h3 id="projectcontour.io/v1alpha1.LogLevel">LogLevel
<th>Description</th>
</tr>
</thead>
<tbody><tr><td><p>&#34;debug&#34;</p></td>
<td><p>DebugLog sets the log level for Contour to <code>debug</code>.</p>
<tbody><tr><td><p>&#34;critical&#34;</p></td>
<td><p>CriticalLog sets the log level for Envoy to <code>critical</code>.</p>
</td>
</tr><tr><td><p>&#34;debug&#34;</p></td>
<td><p>DebugLog sets the log level for Contour/Envoy to <code>debug</code>.</p>
</td>
</tr><tr><td><p>&#34;error&#34;</p></td>
<td><p>ErrorLog sets the log level for Envoy to <code>error</code>.</p>
</td>
</tr><tr><td><p>&#34;info&#34;</p></td>
<td><p>InfoLog sets the log level for Contour to <code>info</code>.</p>
<td><p>InfoLog sets the log level for Contour/Envoy to <code>info</code>.</p>
</td>
</tr><tr><td><p>&#34;off&#34;</p></td>
<td><p>OffLog disable logging for Envoy.</p>
</td>
</tr><tr><td><p>&#34;trace&#34;</p></td>
<td><p>TraceLog sets the log level for Envoy to <code>trace</code>.</p>
</td>
</tr><tr><td><p>&#34;warn&#34;</p></td>
<td><p>WarnLog sets the log level for Envoy to <code>warn</code>.</p>
</td>
</tr></tbody>
</table>
Expand Down

0 comments on commit a11945d

Please sign in to comment.