Skip to content

Commit

Permalink
Merge pull request #36 from rekuberate-io/35-add-random-part-in-cronj…
Browse files Browse the repository at this point in the history
…ob-name

fixed bug adding 12 rand chars #35
  • Loading branch information
akyriako authored Oct 30, 2024
2 parents 0ad95de + 0bb7695 commit 08706bd
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Image URL to use all building/pushing image targets
DOCKER_HUB_NAME ?= $(shell docker info | sed '/Username:/!d;s/.* //')
# sleepcycles
IMG_TAG ?= 0.2.6
IMG_TAG ?= 0.2.7
#IMG_TAG ?= $(shell git rev-parse --short HEAD)
IMG_NAME ?= rekuberate-io-sleepcycles
IMG ?= $(DOCKER_HUB_NAME)/$(IMG_NAME):$(IMG_TAG)
Expand Down
4 changes: 2 additions & 2 deletions charts/sleepcycles/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.2.6
version: 0.2.7
# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "0.2.6"
appVersion: "0.2.7"
2 changes: 1 addition & 1 deletion charts/sleepcycles/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ controllerManager:
- ALL
image:
repository: akyriako78/rekuberate-io-sleepcycles
tag: 0.2.6
tag: 0.2.7
resources:
limits:
cpu: 500m
Expand Down
2 changes: 1 addition & 1 deletion config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ kind: Kustomization
images:
- name: controller
newName: akyriako78/rekuberate-io-sleepcycles
newTag: 0.2.6
newTag: 0.2.7
7 changes: 6 additions & 1 deletion controllers/sleepcycle_runners_cronjobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,13 @@ func (r *SleepCycleReconciler) reconcileCronJob(
}

if cronjob == nil {
cronJobRandomUID, err := r.generateSecureRandomString(12)
if err != nil {
return err
}

cronObjectKey := client.ObjectKey{
Name: fmt.Sprintf("sleepcycle-runner-%s%s-%s", sleepcycle.ObjectMeta.UID[:4], targetMeta.UID[:4], suffix),
Name: fmt.Sprintf("sleepcycle-runner-%s-%s-%s", sleepcycle.ObjectMeta.UID[:4], strings.ToLower(cronJobRandomUID), suffix),
Namespace: sleepcycle.Namespace,
}

Expand Down
17 changes: 16 additions & 1 deletion controllers/sleepcycle_utils.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package controllers

import (
"crypto/rand"
"encoding/base64"
corev1alpha1 "github.com/rekuberate-io/sleepcycles/api/v1alpha1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"math/rand"
"strings"
)

const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"

func (r *SleepCycleReconciler) hasLabel(obj *metav1.ObjectMeta, tag string) bool {
val, ok := obj.GetLabels()[SleepCycleLabel]

Expand All @@ -31,6 +33,19 @@ func (r *SleepCycleReconciler) generateToken() (string, error) {
return base64EncodedToken, nil
}

func (r *SleepCycleReconciler) generateSecureRandomString(length int) (string, error) {
result := make([]byte, length)
_, err := rand.Read(result)
if err != nil {
return "", err
}

for i := range result {
result[i] = letters[int(result[i])%len(letters)]
}
return string(result), nil
}

func (r *SleepCycleReconciler) recordEvent(sleepCycle *corev1alpha1.SleepCycle, message string, isError bool) {
eventType := corev1.EventTypeNormal
reason := "SuccessfulSleepCycleReconcile"
Expand Down

0 comments on commit 08706bd

Please sign in to comment.