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

Cherrypick to k8s 1.26 #908

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
731c650
docs: adjust logos to align center
Xunzhuo Jun 7, 2023
aa348c4
cherry pick main to k8s-1.26
Cloudzp Aug 20, 2024
9b86ab5
upgrade cadvisor
Aug 8, 2023
70729ec
fix nil panic in caculateCPUUsage
borgerli Aug 7, 2023
ca50dfe
monitor recommendation metrics
qmhu Aug 10, 2023
fd78819
fix lint
qmhu Aug 11, 2023
7173fb0
dial remote runtime service in block mode
Aug 30, 2023
015a059
add ContainerResource source type for ehpa prediction
whitebear009 Aug 30, 2023
7672cc0
remove useless function
whitebear009 Aug 30, 2023
1e7431d
extension label for prom query
qmhu Sep 22, 2023
8842693
doc: fix grafana version 6.11.0
zsnmwy Sep 25, 2023
5d0a1d5
fix setup scripts
Oct 11, 2023
8dc5469
fix: strategic merge patch kubernetes
Oct 12, 2023
f6a067e
fix tutorials typo
michaelcheungdk Oct 13, 2023
ce559fa
fix rr controller npe
qmhu Oct 24, 2023
d6e687c
Convergence RBAC permissions
roczzhang Nov 27, 2023
931e5f3
Optimize qos initializer.
payall4u Nov 27, 2023
bc9f557
Fix log level.
payall4u Nov 29, 2023
d6d4d43
Add nil check and add unit test
payall4u Nov 29, 2023
2cf245f
tsp indicator isolated from ehpa
whitebear009 Dec 28, 2023
d06a3f3
fix katex for tsp doc
whitebear009 Dec 28, 2023
445992b
fix oom record sort
whitebear009 Jan 1, 2024
05d7386
change update workload to update workload status
Jan 18, 2024
5c3b431
Fix crane agent panic when pod use ext memory
payall4u Jan 20, 2024
5df5899
fix issues #898
Cloudzp Apr 7, 2024
98437d0
add metrics
Cloudzp Apr 16, 2024
089d4e3
fix ut and fmt error
Cloudzp Apr 17, 2024
8de51a4
fix: close SeedFile
testwill May 12, 2024
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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
[![License](https://img.shields.io/github/license/gocrane/crane)](https://www.apache.org/licenses/LICENSE-2.0.html)
![GoVersion](https://img.shields.io/github/go-mod/go-version/gocrane/crane)

<div align="center">

<img alt="Crane logo" height="100" src="docs/images/crane.svg" title="Crane" width="200"/>

</div>

---

## What is Crane
Expand All @@ -15,8 +19,12 @@

Crane is a FinOps Platform for Cloud Resource Analytics and Economics in Kubernetes clusters. The goal is not only help user to manage cloud cost easier but also ensure the quality of applications.

<div align="center">

<img alt="fcs logo" height="200" src="docs/images/Crane-FinOps-Certified-Solution.png" title="FinOps Certified Solution" width="200"/>

</div>

Crane is a [FinOps Certified Solution](https://www.finops.org/certifications/finops-certified-solution/) project of the [FinOps Foundation](https://www.finops.org/).

**How to start a Cost-Saving journey on Crane?**
Expand Down
8 changes: 8 additions & 0 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
[![License](https://img.shields.io/github/license/gocrane/crane)](https://www.apache.org/licenses/LICENSE-2.0.html)
![GoVersion](https://img.shields.io/github/go-mod/go-version/gocrane/crane)

<div align="center">

<img alt="Crane logo" height="100" src="docs/images/crane.svg" title="Crane" width="200"/>

</div>

---

## Crane 是什么
Expand All @@ -15,8 +19,12 @@

Crane 是一个基于 FinOps 的云资源分析与成本优化平台。它的愿景是在保证客户应用运行质量的前提下实现极致的降本。

<div align="center">

<img alt="fcs logo" height="200" src="docs/images/Crane-FinOps-Certified-Solution.png" title="FinOps Certified Solution" width="200"/>

</div>

Crane 是 [FinOps 基金会](https://www.finops.org/)认证的[云优化方案](https://www.finops.org/certifications/finops-certified-solution/)。

**如何在 Crane 中开启成本优化之旅?**
Expand Down
14 changes: 12 additions & 2 deletions cmd/craned/app/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import (
"github.com/gocrane/crane/pkg/recommendation"
"github.com/gocrane/crane/pkg/server"
serverconfig "github.com/gocrane/crane/pkg/server/config"
"github.com/gocrane/crane/pkg/utils"
"github.com/gocrane/crane/pkg/utils/target"
"github.com/gocrane/crane/pkg/webhooks"
)
Expand Down Expand Up @@ -143,7 +144,7 @@ func Run(ctx context.Context, opts *options.Options) error {
}
}()

initControllers(podOOMRecorder, mgr, opts, predictorMgr, historyDataSources[providers.PrometheusDataSource])
initControllers(ctx, podOOMRecorder, mgr, opts, predictorMgr, historyDataSources[providers.PrometheusDataSource])
// initialize custom collector metrics
initMetricCollector(mgr)
runAll(ctx, mgr, predictorMgr, dataSourceProviders[providers.PrometheusDataSource], opts)
Expand Down Expand Up @@ -256,6 +257,8 @@ func initDataSources(mgr ctrl.Manager, opts *options.Options) (map[providers.Dat
hybridDataSources[providers.PrometheusDataSource] = provider
realtimeDataSources[providers.PrometheusDataSource] = provider
historyDataSources[providers.PrometheusDataSource] = provider

utils.SetExtensionLabels(opts.DataSourcePromConfig.ExtensionLabels)
}
}
return realtimeDataSources, historyDataSources, hybridDataSources
Expand All @@ -266,7 +269,7 @@ func initPredictorManager(opts *options.Options, realtimeDataSources map[provide
}

// initControllers setup controllers with manager
func initControllers(oomRecorder oom.Recorder, mgr ctrl.Manager, opts *options.Options, predictorMgr predictor.Manager, historyDataSource providers.History) {
func initControllers(ctx context.Context, oomRecorder oom.Recorder, mgr ctrl.Manager, opts *options.Options, predictorMgr predictor.Manager, historyDataSource providers.History) {
discoveryClientSet, err := discovery.NewDiscoveryClientForConfig(mgr.GetConfig())
if err != nil {
klog.Exit(err, "Unable to create discover client")
Expand Down Expand Up @@ -417,6 +420,13 @@ func initControllers(oomRecorder oom.Recorder, mgr ctrl.Manager, opts *options.O
}).SetupWithManager(mgr); err != nil {
klog.Exit(err, "unable to create controller", "controller", "RecommendationTriggerController")
}

checker := recommendationctrl.Checker{
Client: mgr.GetClient(),
MonitorInterval: opts.MonitorInterval,
OutDateInterval: opts.OutDateInterval,
}
checker.Run(ctx.Done())
}

// CnpController
Expand Down
9 changes: 9 additions & 0 deletions cmd/craned/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ type Options struct {

// CacheUnstructured indicates whether to cache Unstructured objects. When enabled, it will speed up reading Unstructured objects, but will increase memory usage.
CacheUnstructured bool

// MonitorInterval is the interval for recommendation checker
MonitorInterval time.Duration

// OutDateInterval is the checking interval for identify a recommendation is outdated
OutDateInterval time.Duration
}

// NewOptions builds an empty options.
Expand Down Expand Up @@ -115,6 +121,7 @@ func (o *Options) AddFlags(flags *pflag.FlagSet) {
flags.StringVar(&o.DataSourcePromConfig.AdapterConfigMapKey, "prometheus-adapter-configmap-key", "", "prometheus adapter-configmap key")
flags.StringVar(&o.DataSourcePromConfig.AdapterConfig, "prometheus-adapter-config", "", "prometheus adapter-config path")
flags.StringVar(&o.DataSourcePromConfig.AdapterExtensionLabels, "prometheus-adapter-extension-labels", "", "prometheus adapter extension-labels for expressionQuery")
flags.StringVar(&o.DataSourcePromConfig.ExtensionLabels, "extension-labels", "", "extension-labels for every prometheus query")
flags.StringVar(&o.DataSourcePromConfig.Auth.Username, "prometheus-auth-username", "", "prometheus auth username")
flags.StringVar(&o.DataSourcePromConfig.Auth.Password, "prometheus-auth-password", "", "prometheus auth password")
flags.StringVar(&o.DataSourcePromConfig.Auth.BearerToken, "prometheus-auth-bearertoken", "", "prometheus auth bearertoken")
Expand All @@ -139,4 +146,6 @@ func (o *Options) AddFlags(flags *pflag.FlagSet) {
flags.IntVar(&o.OOMRecordMaxNumber, "oom-record-max-number", 10000, "Max number for oom records to store in configmap")
flags.IntVar(&o.TimeSeriesPredictionMaxConcurrentReconciles, "time-series-prediction-max-concurrent-reconciles", 10, "Max concurrent reconciles for TimeSeriesPrediction controller")
flags.BoolVar(&o.CacheUnstructured, "cache-unstructured", true, "whether to cache Unstructured objects. When enabled, it will speed up reading Unstructured objects but will increase memory usage")
flags.DurationVar(&o.MonitorInterval, "recommendation-monitor-interval", time.Hour, "interval for recommendation checker")
flags.DurationVar(&o.OutDateInterval, "recommendation-outdate-interval", 24*time.Hour, "interval for identify a recommendation is outdated")
}
129 changes: 122 additions & 7 deletions deploy/craned/rbac.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,128 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: craned
namespace: crane-system
rules:
- apiGroups:
- ""
resources:
- configmaps
- secrets
verbs:
- create
- apiGroups:
- ""
resourceNames:
- craned
resources:
- configmaps
verbs:
- get
- patch
- update
- apiGroups:
- ""
resourceNames:
- clusters-secret-store
resources:
- secrets
verbs:
- get
- apiGroups:
- coordination.k8s.io
resources:
- leases
verbs:
- get
- patch
- update
- create
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: craned
rules:
- apiGroups: [ '*' ]
resources: [ '*' ]
verbs: [ "*" ]
- apiGroups:
- ""
resources:
- configmaps
- pods
- nodes
verbs:
- get
- list
- watch
- apiGroups:
- analysis.crane.io
resources:
- "*"
verbs:
- "*"
- apiGroups:
- apps
resources:
- daemonsets
- deployments
- deployments/scale
- statefulsets
- statefulsets/scale
verbs:
- get
- list
- watch
- apiGroups:
- apps
resources:
- daemonsets/status
- deployments/status
- deployments/scale
- statefulsets/status
- statefulsets/scale
verbs:
- update
- apiGroups:
- autoscaling
resources:
- horizontalpodautoscalers
verbs:
- '*'
- apiGroups:
- autoscaling.crane.io
resources:
- '*'
verbs:
- '*'
- apiGroups:
- ""
resources:
- events
verbs:
- create
- patch
- update
- apiGroups:
- prediction.crane.io
resources:
- '*'
verbs:
- '*'
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: craned
namespace: crane-system
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: craned
subjects:
- kind: ServiceAccount
name: craned
namespace: crane-system
---

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
Expand All @@ -17,6 +132,6 @@ roleRef:
kind: ClusterRole
name: craned
subjects:
- kind: ServiceAccount
name: craned
namespace: crane-system
- kind: ServiceAccount
name: craned
namespace: crane-system
Loading
Loading