Skip to content

Commit

Permalink
refactor: make kube-prometheus optional
Browse files Browse the repository at this point in the history
and renaming configmap
  • Loading branch information
pauldotyu committed Apr 12, 2023
1 parent ad0f750 commit 1ea57ba
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 18 deletions.
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,21 @@ kind-delete: kind ## Delete KIND cluster.

.PHONY: kind-deploy
kind-deploy: manifests kustomize docker-build kind-create ## Deploy controller to the K8s cluster specified in ~/.kube/config.
$(KIND) load docker-image ${IMG}
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/default | kubectl apply -f -
kubectl apply -f hack/keda/keda-2.10.0.yaml
kubectl wait --for=condition=Available --timeout=600s apiservice v1beta1.external.metrics.k8s.io
kubectl apply -f hack/workload/deployment.yaml
kubectl apply -f hack/workload/scaledobject.yaml
kubectl apply -f hack/workload/carbonawarekedascaler.yaml

.PHONY: kind-deploy-prom
kind-deploy-prom: manifests kustomize docker-build kind-create ## Deploy controller to the K8s cluster specified in ~/.kube/config.
$(KIND) load docker-image ${IMG}
kubectl apply --server-side -f hack/prometheus/manifests/setup
kubectl wait --for condition=Established --all CustomResourceDefinition --namespace=monitoring
sed -i 's^#- ../prometheus^- ../prometheus^g' config/default/kustomization.yaml
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/default | kubectl apply -f -
kubectl apply -f hack/prometheus/manifests/
Expand Down
2 changes: 1 addition & 1 deletion config/default/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ bases:
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'. 'WEBHOOK' components are required.
#- ../certmanager
# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
- ../prometheus
#- ../prometheus

patchesStrategicMerge:
# Protect the /metrics endpoint by putting it behind auth.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ spec:
carbonIntensityForecastDataSource: # carbon intensity forecast data source
mockCarbonForecast: true # [OPTIONAL] use mock carbon forecast data
localConfigMap: # [OPTIONAL] use configmap for carbon forecast data
name: carbonintensity
name: carbon-intensity
namespace: kube-system
key: data
maxReplicasByCarbonIntensity: # array of carbon intensity values in ascending order; each threshold value represents the upper limit and previous entry represents lower limit
Expand Down
8 changes: 4 additions & 4 deletions controllers/carbon_forecast_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ func (c *CarbonForecastMockConfigMapFetcher) Fetch(ctx context.Context) ([]Carbo

// for 3 hours ago and 7 days in the future loop at each 5 min increment and add a carbon intensity value
for i := -3; i < 7*24*12; i++ {
// generate a random number between 500 and 700
// generate a random number between 529 and 580
rand.Seed(time.Now().UnixNano())
c.CarbonForecast = append(c.CarbonForecast, CarbonForecast{
Timestamp: time.Now().UTC().Add(time.Duration(i*5) * time.Minute),
Value: rand.Float64()*200 + 500,
Value: rand.Float64()*51 + 529,
Duration: 5,
})
}
Expand All @@ -96,8 +96,8 @@ func (c *CarbonForecastMockConfigMapFetcher) Fetch(ctx context.Context) ([]Carbo
// create a configmap and pass carbon forecast as binary data
cm := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: "mock-carbon-forecast",
Namespace: "default",
Name: "carbon-intensity",
Namespace: "kube-system",
},
BinaryData: map[string][]byte{
"data": forecast,
Expand Down
12 changes: 6 additions & 6 deletions controllers/carbonawarekedascaler_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ var _ = Describe("scenarios for the carbon aware KEDA Scaler", func() {
Context("the controller should be able to mocked data for demo purposes", func() {
When("carbonawarekedascaler is set to use mocked data", func() {
const (
configMapName = "mock-carbon-forecast"
configMapNamespace = "default"
configMapName = "carbon-intensity"
configMapNamespace = "kube-system"
configMapKey = "data"
)
It("will save forecast data in a ConfigMap", func() {
Expand All @@ -52,7 +52,7 @@ var _ = Describe("scenarios for the carbon aware KEDA Scaler", func() {
Expect(cf).ShouldNot(BeNil())

cm := &corev1.ConfigMap{}
By("Confirming the ConfigMap named mock-carbon-forecast is found")
By("Confirming the ConfigMap named carbon-intensity is found")
Expect(k8sClient.Get(ctx, client.ObjectKey{Name: configMapName, Namespace: configMapNamespace}, cm)).Should(Succeed())
})
})
Expand Down Expand Up @@ -132,8 +132,8 @@ var _ = Describe("scenarios for the carbon aware KEDA Scaler", func() {
carbonAwareKedaScalerName = "test-carbonawarekedascaler"
carbonAwareKedaScalerNamespace = "default"
carbonAwareKedaScalerKedaTarget = "scaledobjects.keda.sh"
configMapName = "mock-carbon-forecast"
configMapNamespace = "default"
configMapName = "carbon-intensity"
configMapNamespace = "kube-system"
configMapKey = "data"
timeout = time.Second * 5
interval = time.Millisecond * 250
Expand Down Expand Up @@ -257,7 +257,7 @@ var _ = Describe("scenarios for the carbon aware KEDA Scaler", func() {

When("the carbon intensity is within a configured range", func() {
const (
testConfigMapName = "carbonintensity"
testConfigMapName = "mock-carbon-intensity"
testConfigMapNamespace = "kube-system"
testConfigMapKey = "data"
)
Expand Down
12 changes: 6 additions & 6 deletions hack/workload/carbonawarekedascaler.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ spec:
carbonIntensityForecastDataSource: # carbon intensity forecast data source
mockCarbonForecast: true # [OPTIONAL] use mock carbon forecast data
localConfigMap: # [OPTIONAL] use configmap for carbon forecast data
name: carbonintensity
name: carbon-intensity
namespace: kube-system
key: data
maxReplicasByCarbonIntensity: # array of carbon intensity values in ascending order; each threshold value represents the upper limit and previous entry represents lower limit
- carbonIntensityThreshold: 562 # when carbon intensity is 562 or below
- carbonIntensityThreshold: 543 # when carbon intensity is 543 or below
maxReplicas: 15 # do more
- carbonIntensityThreshold: 575 # when carbon intensity is >562 and <=575
- carbonIntensityThreshold: 561 # when carbon intensity is >544 and <=561
maxReplicas: 8
- carbonIntensityThreshold: 589 # when carbon intensity is >575 and <=589 (or above)
- carbonIntensityThreshold: 579 # when carbon intensity is >562 and <=579 (or above)
maxReplicas: 1 # do less
ecoModeOff: # [OPTIONAL] settings to override carbon awareness; can override based on high intensity duration or schedules
maxReplicas: 10 # when carbon awareness is disabled, use this value
maxReplicas: 100 # when carbon awareness is disabled, use this value
carbonIntensityDuration: # [OPTIONAL] disable carbon awareness when carbon intensity is high for this length of time
carbonIntensityThreshold: 588 # when carbon intensity is equal to or above this value, consider it high
carbonIntensityThreshold: 555 # when carbon intensity is equal to or above this value, consider it high
overrideEcoAfterDurationInMins: 60 # if carbon intensity is high for this many hours disable ecomode
customSchedule: # [OPTIONAL] disable carbon awareness during specified time periods
- startTime: "2023-03-31T16:45:00Z" # start time in UTC
Expand Down

0 comments on commit 1ea57ba

Please sign in to comment.