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

Optimize qos initializer. #878

Merged
merged 3 commits into from
Nov 30, 2023
Merged

Conversation

payall4u
Copy link
Collaborator

What type of PR is this?

Feature.

What this PR does / why we need it:

Optimize qos initializer webhook. Inject init-container and init-volume only when pod matched by offline pod qos.

Which issue(s) this PR fixes:

From #876

Special notes for your reviewer:

Copy link
Contributor

github-actions bot commented Nov 29, 2023

🎉 Successfully Build Images.
Now Support ARM Platforms.
Comment Post Time: 2023-11-29 20:45
Git Version: 74132af

Docker Registry

Overview: https://hub.docker.com/u/gocrane

Image Pull Command
crane-agent:pr-878-74132af docker pull gocrane/crane-agent:pr-878-74132af
dashboard:pr-878-74132af docker pull gocrane/dashboard:pr-878-74132af
metric-adapter:pr-878-74132af docker pull gocrane/metric-adapter:pr-878-74132af
craned:pr-878-74132af docker pull gocrane/craned:pr-878-74132af

Quick Deploy - Helm

helm repo add crane https://finops-helm.pkg.coding.net/gocrane/gocrane
helm install crane -n crane-system --create-namespace \
                   --set craned.image.repository=gocrane/craned \
                   --set craned.image.tag=pr-878-74132af \
                   --set metricAdapter.image.repository=gocrane/metric-adapter \
                   --set metricAdapter.image.tag=pr-878-74132af \
                   --set craneAgent.image.repository=gocrane/crane-agent \
                   --set craneAgent.image.tag=pr-878-74132af \
                   --set cranedDashboard.image.repository=gocrane/dashboard \
                   --set cranedDashboard.image.tag=pr-878-74132af crane/crane

Coding Registry

Overview: https://finops.coding.net/public-artifacts/gocrane/crane/packages

Image Pull Command
crane-agent:pr-878-74132af docker pull finops-docker.pkg.coding.net/gocrane/crane/crane-agent:pr-878-74132af
dashboard:pr-878-74132af docker pull finops-docker.pkg.coding.net/gocrane/crane/dashboard:pr-878-74132af
metric-adapter:pr-878-74132af docker pull finops-docker.pkg.coding.net/gocrane/crane/metric-adapter:pr-878-74132af
craned:pr-878-74132af docker pull finops-docker.pkg.coding.net/gocrane/crane/craned:pr-878-74132af

Quick Deploy - Helm

helm repo add crane https://finops-helm.pkg.coding.net/gocrane/gocrane
helm install crane -n crane-system --create-namespace \
                   --set craned.image.repository=finops-docker.pkg.coding.net/gocrane/crane/craned \
                   --set craned.image.tag=pr-878-74132af \
                   --set metricAdapter.image.repository=finops-docker.pkg.coding.net/gocrane/crane/metric-adapter \
                   --set metricAdapter.image.tag=pr-878-74132af \
                   --set craneAgent.image.repository=finops-docker.pkg.coding.net/gocrane/crane/crane-agent \
                   --set craneAgent.image.tag=pr-878-74132af \
                   --set cranedDashboard.image.repository=finops-docker.pkg.coding.net/gocrane/crane/dashboard \
                   --set cranedDashboard.image.tag=pr-878-74132af crane/crane

Ghcr Registry

Overview: https://github.com/orgs/gocrane/packages?repo_name=crane

Image Pull Command
crane-agent:pr-878-74132af docker pull ghcr.io/gocrane/crane/crane-agent:pr-878-74132af
dashboard:pr-878-74132af docker pull ghcr.io/gocrane/crane/dashboard:pr-878-74132af
metric-adapter:pr-878-74132af docker pull ghcr.io/gocrane/crane/metric-adapter:pr-878-74132af
craned:pr-878-74132af docker pull ghcr.io/gocrane/crane/craned:pr-878-74132af

Quick Deploy - Helm

helm repo add crane https://finops-helm.pkg.coding.net/gocrane/gocrane
helm install crane -n crane-system --create-namespace \
                   --set craned.image.repository=ghcr.io/gocrane/crane/craned \
                   --set craned.image.tag=pr-878-74132af \
                   --set metricAdapter.image.repository=ghcr.io/gocrane/crane/metric-adapter \
                   --set metricAdapter.image.tag=pr-878-74132af \
                   --set craneAgent.image.repository=ghcr.io/gocrane/crane/crane-agent \
                   --set craneAgent.image.tag=pr-878-74132af \
                   --set cranedDashboard.image.repository=ghcr.io/gocrane/crane/dashboard \
                   --set cranedDashboard.image.tag=pr-878-74132af crane/crane

matchLabels:
app: nginx
initContainerTemplate:
name: crane-qos-initializer
name: qos-initializer-container
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: name: qos-initializer is fine

image: docker.io/gocrane/qos-init:v0.1.6
imagePullPolicy: IfNotPresent
args:
- "while ! grep -q gocrane.io/cpu-qos /etc/podinfo/annotations; do sleep 1; done; echo cpu qos setting competed;"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it's just a shell call, do we still need qos-init image, can it be changed to pause?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, pause does not contain those shell command, ignore this

@@ -28,7 +40,7 @@ func (m *MutatingAdmission) Default(ctx context.Context, obj runtime.Object) err
return fmt.Errorf("expected a Pod but got a %T", obj)
}

klog.Infof("Into Pod injection %s/%s", pod.Namespace, pod.Name)
klog.Infof("mutating started for pod %s/%s", pod.Namespace, pod.Name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A code standard, all logs start with Capital letters, and please check if a log level should be added and disabled the msg by default. same suggestion to all newly added logs

if m.Config.QOSInitializer.InitContainerTemplate != nil {
pod.Spec.InitContainers = append(pod.Spec.InitContainers, *m.Config.QOSInitializer.InitContainerTemplate)
if !ls.Matches(labels.Set(pod.Labels)) {
klog.Infof("injection skipped: webhook is not interested in the pod")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

injection->Injection, and this is a debug log, I suggest to add a log level and do not enable by default, and if we have label config for the webhook, this line of code should not be called?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, I don't like this logic. But in order to be compatible with the previous design, I still leave the matching here.

@@ -6,6 +6,8 @@ import (
"strings"
"time"

"github.com/gocrane/crane/pkg/ensurance/util"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this to the crane import section

pkg/webhooks/pod/mutating.go Outdated Show resolved Hide resolved
pkg/webhooks/pod/mutating.go Show resolved Hide resolved
Copy link
Contributor

@mfanjie mfanjie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mfanjie mfanjie merged commit 6d7758e into gocrane:main Nov 30, 2023
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants