Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[main][SRVKS-1286] Override activator termination grace perio… #3017

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func InjectRbacProxyContainer(deployments sets.Set[string], cfg base.ConfigMapDa
}
logLevel := DefaultKubeRbacProxyLogLevel
if cfg != nil {
if deploymentData := getCmDataforName(cfg, "config-deployment"); deploymentData != nil {
if deploymentData := GetCmDataforName(cfg, "config-deployment"); deploymentData != nil {
if cpuRequest, ok := deploymentData["kube-rbac-proxy-cpu-request"]; ok {
resources.Requests["cpu"] = resource.MustParse(cpuRequest)
}
Expand All @@ -49,7 +49,7 @@ func InjectRbacProxyContainer(deployments sets.Set[string], cfg base.ConfigMapDa
resources.Limits["memory"] = resource.MustParse(memLimit)
}
}
if loggingData := getCmDataforName(cfg, "config-logging"); loggingData != nil {
if loggingData := GetCmDataforName(cfg, "config-logging"); loggingData != nil {
if logLevelStr, ok := loggingData["loglevel.kube-rbac-proxy"]; ok {
logLevel, _ = strconv.Atoi(logLevelStr)
}
Expand Down Expand Up @@ -142,7 +142,7 @@ func ExtensionDeploymentOverrides(overrides []base.WorkloadOverride, deployments
return operator.OverridesTransform(ovs, nil)
}

func getCmDataforName(cfg base.ConfigMapData, name string) map[string]string {
func GetCmDataforName(cfg base.ConfigMapData, name string) map[string]string {
if cfg[name] != nil {
return cfg[name]
}
Expand Down
30 changes: 30 additions & 0 deletions openshift-knative-operator/pkg/serving/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"os"
"strconv"
"strings"
"sync/atomic"

Expand All @@ -13,11 +14,14 @@ import (
"github.com/openshift-knative/serverless-operator/pkg/client/clientset/versioned"
ocpclient "github.com/openshift-knative/serverless-operator/pkg/client/injection/client"
socommon "github.com/openshift-knative/serverless-operator/pkg/common"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/tools/cache"
"knative.dev/operator/pkg/apis/operator/base"
operatorv1beta1 "knative.dev/operator/pkg/apis/operator/v1beta1"
Expand All @@ -35,6 +39,7 @@ const (
defaultDomainTemplate = "{{.Name}}-{{.Namespace}}.{{.Domain}}"
networkingCertificatesReconcilerLease = "controller.knative.dev.networking.pkg.certificates.reconciler.reconciler"
controlProtocolCertificatesReconcilerLease = "controller.knative.dev.control-protocol.pkg.certificates.reconciler.reconciler"
maxRevisionTimeoutSeconds = "max-revision-timeout-seconds"
)

var oldResourceRemoved atomic.Bool
Expand Down Expand Up @@ -90,6 +95,7 @@ func (e *extension) Transformers(ks base.KComponent) []mf.Transformer {
}
tf = append(tf, enableSecretInformerFilteringTransformers(ks)...)
tf = append(tf, monitoring.GetServingTransformers(ks)...)
tf = append(tf, overrideActivatorTerminationGracePeriod(ks))
return append(tf, common.DeprecatedAPIsTranformers(e.kubeclient.Discovery())...)
}

Expand Down Expand Up @@ -259,3 +265,27 @@ func (e *extension) cleanupOldResources(ctx context.Context, ns string) error {

return nil
}

func overrideActivatorTerminationGracePeriod(ks base.KComponent) mf.Transformer {
comp := ks.(*operatorv1beta1.KnativeServing)
if v := monitoring.GetCmDataforName(comp.Spec.Config, "config-defaults"); v != nil {
if maxTimeout, ok := v[maxRevisionTimeoutSeconds]; ok {
return func(u *unstructured.Unstructured) error {
if u.GetKind() == "Deployment" && u.GetName() == "activator" {
dep := &appsv1.Deployment{}
if err := scheme.Scheme.Convert(u, dep, nil); err != nil {
return err
}
parsedMaxTimeout, err := strconv.ParseInt(maxTimeout, 10, 64)
if err != nil {
return err
}
dep.Spec.Template.Spec.TerminationGracePeriodSeconds = ptr.Int64(parsedMaxTimeout)
return scheme.Scheme.Convert(dep, u, nil)
}
return nil
}
}
}
return nil
}
Loading