forked from grafana/loki
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
operator: React to changes in ConfigMap used for storage CA (grafana#…
- Loading branch information
1 parent
326b683
commit f762b71
Showing
7 changed files
with
110 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 34 additions & 5 deletions
39
operator/internal/handlers/internal/storage/ca_configmap.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,38 @@ | ||
package storage | ||
|
||
import corev1 "k8s.io/api/core/v1" | ||
import ( | ||
"crypto/sha1" | ||
"fmt" | ||
|
||
// IsValidCAConfigMap checks if the given CA configMap has an | ||
// non-empty entry for the key | ||
func IsValidCAConfigMap(cm *corev1.ConfigMap, key string) bool { | ||
return cm.Data[key] != "" | ||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
type caKeyError string | ||
|
||
func (e caKeyError) Error() string { | ||
return fmt.Sprintf("key not present or data empty: %s", string(e)) | ||
} | ||
|
||
// CheckCAConfigMap checks if the given CA configMap has an non-empty entry for the key used as CA certificate. | ||
// If the key is present it will return a hash of the current key name and contents. | ||
func CheckCAConfigMap(cm *corev1.ConfigMap, key string) (string, error) { | ||
data := cm.Data[key] | ||
if data == "" { | ||
return "", caKeyError(key) | ||
} | ||
|
||
h := sha1.New() | ||
if _, err := h.Write([]byte(key)); err != nil { | ||
return "", err | ||
} | ||
|
||
if _, err := h.Write(hashSeparator); err != nil { | ||
return "", err | ||
} | ||
|
||
if _, err := h.Write([]byte(data)); err != nil { | ||
return "", err | ||
} | ||
|
||
return fmt.Sprintf("%x", h.Sum(nil)), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters