Skip to content

Commit 157cf0f

Browse files
Remove SHA1 changes
Signed-off-by: faizanahmad055 <faizan.ahmad55@outlook.com>
1 parent 6fd7c82 commit 157cf0f

6 files changed

Lines changed: 32 additions & 26 deletions

File tree

docs/How-it-works.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ Note: Rolling upgrade also works in the same way for secrets.
7676

7777
### Hash Value Computation
7878

79-
Reloader uses SHA512 to compute hash value. SHA1 is used because it is efficient and less prone to collision.
79+
Reloader uses SHA1 to compute hash value. SHA1 is used because it is efficient and less prone to collision.
8080

8181
## Monitor All Namespaces
8282

@@ -90,4 +90,4 @@ The output file can then be used to deploy Reloader in specific namespace.
9090

9191
## Compatibility With Helm Install and Upgrade
9292

93-
Reloader has no impact on helm deployment cycle. Reloader only injects an environment variable in `deployment`, `daemonset` or `statefulset`. The environment variable contains the SHA512 value of `ConfigMaps` or `Secrets` data. So if a deployment is created using Helm and Reloader updates the deployment, then next time you upgrade the helm release, Reloader will do nothing except changing that environment variable value in `deployment` , `daemonset` or `statefulset`.
93+
Reloader has no impact on helm deployment cycle. Reloader only injects an environment variable in `deployment`, `daemonset` or `statefulset`. The environment variable contains the SHA1 value of `ConfigMaps` or `Secrets` data. So if a deployment is created using Helm and Reloader updates the deployment, then next time you upgrade the helm release, Reloader will do nothing except changing that environment variable value in `deployment` , `daemonset` or `statefulset`.

docs/Reloader-vs-ConfigmapController.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
Reloader is inspired from [`configmapcontroller`](https://github.com/fabric8io/configmapcontroller) but there are many ways in which it differs from `configmapcontroller`. Below is the small comparison between these two controllers.
44

5-
| Reloader | ConfigMap |
6-
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
7-
| Reloader can watch both `Secrets` and `ConfigMaps`. | `configmapcontroller` can only watch changes in `ConfigMaps`. It cannot detect changes in other resources like `Secrets`. |
8-
| Reloader can perform rolling upgrades on `deployments` as well as on `statefulsets` and `daemonsets` | `configmapcontroller` can only perform rolling upgrades on `deployments`. It currently does not support rolling upgrades on `statefulsets` and `daemonsets` |
9-
| Reloader provides both unit test cases and end to end integration test cases for future updates. So one can make sure that new changes do not break any old functionality. | Currently there are not any unit test cases or end to end integration test cases in `configmap-controller`. It adds difficulties for any additional updates in `configmap-controller` and one can not know for sure whether new changes breaks any old functionality or not. |
10-
| Reloader uses SHA512 to encode the change in `ConfigMap` or `Secret`. It then saves the SHA1 value in `STAKATER_FOO_CONFIGMAP` or `STAKATER_FOO_SECRET` environment variable depending upon where the change has happened. The use of SHA1 provides a concise 40 characters encoded value that is very less prone to collision. | `configmap-controller` uses `FABRICB_FOO_REVISION` environment variable to store any change in `ConfigMap` controller. It does not encode it or convert it in suitable hash value to avoid data pollution in deployment. |
11-
| Reloader allows you to customize your own annotation (for both `Secrets` and `ConfigMaps`) using command line flags | `configmap-controller` restricts you to only their provided annotation |
5+
| Reloader | ConfigMap |
6+
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
7+
| Reloader can watch both `Secrets` and `ConfigMaps`. | `configmapcontroller` can only watch changes in `ConfigMaps`. It cannot detect changes in other resources like `Secrets`. |
8+
| Reloader can perform rolling upgrades on `deployments` as well as on `statefulsets` and `daemonsets` | `configmapcontroller` can only perform rolling upgrades on `deployments`. It currently does not support rolling upgrades on `statefulsets` and `daemonsets` |
9+
| Reloader provides both unit test cases and end to end integration test cases for future updates. So one can make sure that new changes do not break any old functionality. | Currently there are not any unit test cases or end to end integration test cases in `configmap-controller`. It adds difficulties for any additional updates in `configmap-controller` and one can not know for sure whether new changes breaks any old functionality or not. |
10+
| Reloader uses SHA1 to encode the change in `ConfigMap` or `Secret`. It then saves the SHA1 value in `STAKATER_FOO_CONFIGMAP` or `STAKATER_FOO_SECRET` environment variable depending upon where the change has happened. The use of SHA1 provides a concise 40 characters encoded value that is very less prone to collision. | `configmap-controller` uses `FABRICB_FOO_REVISION` environment variable to store any change in `ConfigMap` controller. It does not encode it or convert it in suitable hash value to avoid data pollution in deployment. |
11+
| Reloader allows you to customize your own annotation (for both `Secrets` and `ConfigMaps`) using command line flags | `configmap-controller` restricts you to only their provided annotation |

docs/Reloader-vs-k8s-trigger-controller.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Reloader and k8s-trigger-controller are both built for same purpose. So there ar
66

77
- Both controllers support change detection in `ConfigMaps` and `Secrets`
88
- Both controllers support deployment `rollout`
9-
- Reloader controller use SHA512 for hashing
9+
- Reloader controller use SHA1 for hashing
1010
- Both controllers have end to end as well as unit test cases.
1111

1212
## Differences

internal/pkg/crypto/sha.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
package crypto
22

33
import (
4-
"crypto/sha512"
5-
"encoding/hex"
4+
"crypto/sha1"
5+
"fmt"
6+
"io"
7+
8+
"github.com/sirupsen/logrus"
69
)
710

811
// GenerateSHA generates SHA from string
9-
// Always returns a hash value, even for empty strings, to ensure consistent behavior
10-
// and avoid issues with string matching operations (e.g., strings.Contains(str, "") always returns true)
1112
func GenerateSHA(data string) string {
12-
hash := sha512.Sum512_256([]byte(data))
13-
return hex.EncodeToString(hash[:])
13+
hasher := sha1.New()
14+
_, err := io.WriteString(hasher, data)
15+
if err != nil {
16+
logrus.Errorf("Unable to write data in hash writer %v", err)
17+
}
18+
sha := hasher.Sum(nil)
19+
return fmt.Sprintf("%x", sha)
1420
}

internal/pkg/crypto/sha_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
// TestGenerateSHA generates the sha from given data and verifies whether it is correct or not
88
func TestGenerateSHA(t *testing.T) {
99
data := "www.stakater.com"
10-
sha := "2e9aa975331b22861b4f62b7fcc69b63e001f938361fee3b4ed888adf26a10e3"
10+
sha := "abd4ed82fb04548388a6cf3c339fd9dc84d275df"
1111
result := GenerateSHA(data)
1212
if result != sha {
1313
t.Errorf("Failed to generate SHA")
@@ -18,11 +18,11 @@ func TestGenerateSHA(t *testing.T) {
1818
// This ensures consistent behavior and avoids issues with string matching operations
1919
func TestGenerateSHAEmptyString(t *testing.T) {
2020
result := GenerateSHA("")
21-
expected := "c672b8d1ef56ed28ab87c3622c5114069bdd3ad7b8f9737498d0c01ecef0967a"
21+
expected := "da39a3ee5e6b4b0d3255bfef95601890afd80709"
2222
if result != expected {
2323
t.Errorf("Failed to generate SHA for empty string. Expected: %s, Got: %s", expected, result)
2424
}
25-
if len(result) != 64 {
26-
t.Errorf("SHA hash should be 64 characters long, got %d", len(result))
25+
if len(result) != 40 {
26+
t.Errorf("SHA hash should be 40 characters long, got %d", len(result))
2727
}
2828
}

internal/pkg/handler/upgrade_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1981,7 +1981,7 @@ func TestRollingUpgradeForDeploymentWithPatchAndRetryUsingArs(t *testing.T) {
19811981
assert.Equal(t, patchtypes.StrategicMergePatchType, patchType)
19821982
assert.NotEmpty(t, bytes)
19831983
assert.Contains(t, string(bytes), `{"spec":{"template":{"metadata":{"annotations":{"reloader.stakater.com/last-reloaded-from":`)
1984-
assert.Contains(t, string(bytes), `\"hash\":\"fd9e71a362056bfa864d9859e12978f893d330ce8cbf09218b25d015770ad91f\"`)
1984+
assert.Contains(t, string(bytes), `\"hash\":\"3c9a892aeaedc759abc3df9884a37b8be5680382\"`)
19851985
return nil
19861986
}
19871987

@@ -2964,7 +2964,7 @@ func TestRollingUpgradeForDaemonSetWithPatchAndRetryUsingArs(t *testing.T) {
29642964
assert.Equal(t, patchtypes.StrategicMergePatchType, patchType)
29652965
assert.NotEmpty(t, bytes)
29662966
assert.Contains(t, string(bytes), `{"spec":{"template":{"metadata":{"annotations":{"reloader.stakater.com/last-reloaded-from":`)
2967-
assert.Contains(t, string(bytes), `\"hash\":\"43bf9e30e7c4e32a8f8673c462b86d0b1ac626cf498afdc0d0108e79ebe7ee0c\"`)
2967+
assert.Contains(t, string(bytes), `\"hash\":\"314a2269170750a974d79f02b5b9ee517de7f280\"`)
29682968
return nil
29692969
}
29702970

@@ -3227,7 +3227,7 @@ func TestRollingUpgradeForStatefulSetWithPatchAndRetryUsingArs(t *testing.T) {
32273227
assert.Equal(t, patchtypes.StrategicMergePatchType, patchType)
32283228
assert.NotEmpty(t, bytes)
32293229
assert.Contains(t, string(bytes), `{"spec":{"template":{"metadata":{"annotations":{"reloader.stakater.com/last-reloaded-from":`)
3230-
assert.Contains(t, string(bytes), `\"hash\":\"6aa837180bdf6a93306c71a0cf62b4a45c2d5b021578247b3b64d5baea2b84d9\"`)
3230+
assert.Contains(t, string(bytes), `\"hash\":\"f821414d40d8815fb330763f74a4ff7ab651d4fa\"`)
32313231
return nil
32323232
}
32333233

@@ -3607,7 +3607,7 @@ func TestRollingUpgradeForDeploymentWithPatchAndRetryUsingErs(t *testing.T) {
36073607
assert.Equal(t, patchtypes.StrategicMergePatchType, patchType)
36083608
assert.NotEmpty(t, bytes)
36093609
assert.Contains(t, string(bytes), `{"spec":{"template":{"spec":{"containers":[{"name":`)
3610-
assert.Contains(t, string(bytes), `"value":"fd9e71a362056bfa864d9859e12978f893d330ce8cbf09218b25d015770ad91f"`)
3610+
assert.Contains(t, string(bytes), `"value":"3c9a892aeaedc759abc3df9884a37b8be5680382"`)
36113611
return nil
36123612
}
36133613

@@ -4502,7 +4502,7 @@ func TestRollingUpgradeForDaemonSetWithPatchAndRetryUsingErs(t *testing.T) {
45024502
assert.Equal(t, patchtypes.StrategicMergePatchType, patchType)
45034503
assert.NotEmpty(t, bytes)
45044504
assert.Contains(t, string(bytes), `{"spec":{"template":{"spec":{"containers":[{"name":`)
4505-
assert.Contains(t, string(bytes), `"value":"43bf9e30e7c4e32a8f8673c462b86d0b1ac626cf498afdc0d0108e79ebe7ee0c"`)
4505+
assert.Contains(t, string(bytes), `"value":"314a2269170750a974d79f02b5b9ee517de7f280"`)
45064506
return nil
45074507
}
45084508

@@ -4737,7 +4737,7 @@ func TestRollingUpgradeForStatefulSetWithPatchAndRetryUsingErs(t *testing.T) {
47374737
assert.Equal(t, patchtypes.StrategicMergePatchType, patchType)
47384738
assert.NotEmpty(t, bytes)
47394739
assert.Contains(t, string(bytes), `{"spec":{"template":{"spec":{"containers":[{"name":`)
4740-
assert.Contains(t, string(bytes), `"value":"6aa837180bdf6a93306c71a0cf62b4a45c2d5b021578247b3b64d5baea2b84d9"`)
4740+
assert.Contains(t, string(bytes), `"value":"f821414d40d8815fb330763f74a4ff7ab651d4fa"`)
47414741
return nil
47424742
}
47434743

0 commit comments

Comments
 (0)