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

feat: Support trigger a recommendation manually #714

Merged
merged 2 commits into from
Mar 17, 2023

Conversation

qmhu
Copy link
Member

@qmhu qmhu commented Mar 9, 2023

What type of PR is this?

Feature

What this PR does / why we need it:

Manually triggering a recommendation can be done through the following steps:

  1. Obtain the runNumber from the recommendationRule.

image

  1. Modify the run number annotation for the recommendation that should be triggered. The run number should be lower than the runNumber in the recommendationRule. For example, if recommendationRule.status.runNumber=6, then change the annotation value to 5.

image

  1. The recommendationRule controller checks for updates every 10 seconds. Once it detects the modified run number, it triggers the recommendation flow and updates the recommendationRule.status and recommendation. The recommendation's runNumber is modified to match that of the recommendationRule. You can use this to know when the manual trigger is finished.

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

@qmhu qmhu changed the title Support trigger a recommendation manually feat: Support trigger a recommendation manually Mar 9, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Mar 9, 2023

🎉 Successfully Build Images.
Now Support ARM Platforms.
Comment Post Time: 2023-03-14 16:25
Git Version: 69a7c13

Docker Registry

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

Image Pull Command
crane-agent:pr-714-69a7c13 docker pull gocrane/crane-agent:pr-714-69a7c13
dashboard:pr-714-69a7c13 docker pull gocrane/dashboard:pr-714-69a7c13
metric-adapter:pr-714-69a7c13 docker pull gocrane/metric-adapter:pr-714-69a7c13
craned:pr-714-69a7c13 docker pull gocrane/craned:pr-714-69a7c13

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-714-69a7c13 \
                   --set metricAdapter.image.repository=gocrane/metric-adapter \
                   --set metricAdapter.image.tag=pr-714-69a7c13 \
                   --set craneAgent.image.repository=gocrane/crane-agent \
                   --set craneAgent.image.tag=pr-714-69a7c13 \
                   --set cranedDashboard.image.repository=gocrane/dashboard \
                   --set cranedDashboard.image.tag=pr-714-69a7c13 crane/crane

Coding Registry

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

Image Pull Command
crane-agent:pr-714-69a7c13 docker pull finops-docker.pkg.coding.net/gocrane/crane/crane-agent:pr-714-69a7c13
dashboard:pr-714-69a7c13 docker pull finops-docker.pkg.coding.net/gocrane/crane/dashboard:pr-714-69a7c13
metric-adapter:pr-714-69a7c13 docker pull finops-docker.pkg.coding.net/gocrane/crane/metric-adapter:pr-714-69a7c13
craned:pr-714-69a7c13 docker pull finops-docker.pkg.coding.net/gocrane/crane/craned:pr-714-69a7c13

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-714-69a7c13 \
                   --set metricAdapter.image.repository=finops-docker.pkg.coding.net/gocrane/crane/metric-adapter \
                   --set metricAdapter.image.tag=pr-714-69a7c13 \
                   --set craneAgent.image.repository=finops-docker.pkg.coding.net/gocrane/crane/crane-agent \
                   --set craneAgent.image.tag=pr-714-69a7c13 \
                   --set cranedDashboard.image.repository=finops-docker.pkg.coding.net/gocrane/crane/dashboard \
                   --set cranedDashboard.image.tag=pr-714-69a7c13 crane/crane

Ghcr Registry

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

Image Pull Command
crane-agent:pr-714-69a7c13 docker pull ghcr.io/gocrane/crane/crane-agent:pr-714-69a7c13
dashboard:pr-714-69a7c13 docker pull ghcr.io/gocrane/crane/dashboard:pr-714-69a7c13
metric-adapter:pr-714-69a7c13 docker pull ghcr.io/gocrane/crane/metric-adapter:pr-714-69a7c13
craned:pr-714-69a7c13 docker pull ghcr.io/gocrane/crane/craned:pr-714-69a7c13

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-714-69a7c13 \
                   --set metricAdapter.image.repository=ghcr.io/gocrane/crane/metric-adapter \
                   --set metricAdapter.image.tag=pr-714-69a7c13 \
                   --set craneAgent.image.repository=ghcr.io/gocrane/crane/crane-agent \
                   --set craneAgent.image.tag=pr-714-69a7c13 \
                   --set cranedDashboard.image.repository=ghcr.io/gocrane/crane/dashboard \
                   --set cranedDashboard.image.tag=pr-714-69a7c13 crane/crane

@whitebear009
Copy link
Contributor

It seems that only a single recommendation can be manually executed. Is it necessary to support manual execution of the recommendationrule?

@qmhu
Copy link
Member Author

qmhu commented Mar 14, 2023

Last implement has a limitation: if the recommendation rule controller is reconciling, the manual trigger will wait, this is unexpectable. So we use a trigger controller to watch the decrease event.

How to trigger a recommendationRule is trick work. We can't modify the spec, but recommendationRule controller only watch spec changes...

@qmhu
Copy link
Member Author

qmhu commented Mar 15, 2023

@whitebear009 PTAL

klog.V(6).Infof("recommendation %s OnUpdate", klog.KObj(newRecommendation))

oldRunNumber, _ := utils.GetRunNumber(oldRecommendation)
newRunNumber, _ := utils.GetRunNumber(newRecommendation)
Copy link
Contributor

Choose a reason for hiding this comment

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

the error is not handled

Copy link
Member Author

Choose a reason for hiding this comment

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

if get run number failed , we treat it as a empty number which by default is 0.

@whitebear009
Copy link
Contributor

/lgtm

@qmhu qmhu merged commit d5d5508 into gocrane:main Mar 17, 2023
@qmhu qmhu linked an issue Mar 24, 2023 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Trigger a recommendationRule to run now
2 participants