-
Notifications
You must be signed in to change notification settings - Fork 806
Feat: support tracking binaryData in CM #1929
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
base: main
Are you sure you want to change the base?
Changes from 4 commits
aafba3c
beef790
f3fa6a1
29c33c0
171432d
fd7ed6b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| # Flagger Governance | ||
|
|
||
| The Flagger project is governed by the [Flux governance document](https://github.com/fluxcd/community/blob/main/GOVERNANCE.md), | ||
| involvement is defined in the [Flux community roles document](chttps://github.com/fluxcd/community/blob/main/community-roles.md), | ||
| involvement is defined in the [Flux community roles document](https://github.com/fluxcd/community/blob/main/community-roles.md), | ||
| and processes can be found in the [Flux process document](https://github.com/fluxcd/community/blob/main/PROCESS.md). |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ import ( | |
| "crypto/sha256" | ||
| "encoding/json" | ||
| "fmt" | ||
| "maps" | ||
| "strings" | ||
|
|
||
| "go.uber.org/zap" | ||
|
|
@@ -36,9 +37,10 @@ import ( | |
|
|
||
| // ConfigTracker is managing the operations for Kubernetes ConfigMaps and Secrets | ||
| type ConfigTracker struct { | ||
| KubeClient kubernetes.Interface | ||
| FlaggerClient clientset.Interface | ||
| Logger *zap.SugaredLogger | ||
| KubeClient kubernetes.Interface | ||
| FlaggerClient clientset.Interface | ||
| Logger *zap.SugaredLogger | ||
| TrackBinaryData bool | ||
| } | ||
|
|
||
| type ConfigRefType string | ||
|
|
@@ -88,7 +90,7 @@ func (ct *ConfigTracker) getRefFromConfigMap(name string, namespace string) (*Co | |
| return &ConfigRef{ | ||
| Name: config.Name, | ||
| Type: ConfigRefMap, | ||
| Checksum: checksum(config.Data), | ||
| Checksum: checksum(ct.getDataFromConfigMap(*config)), | ||
| }, nil | ||
| } | ||
|
|
||
|
|
@@ -120,6 +122,20 @@ func (ct *ConfigTracker) getRefFromSecret(name string, namespace string) (*Confi | |
| }, nil | ||
| } | ||
|
|
||
| // getDataFromConfigMap fetches both data and binaryData with regards to TrackBinaryData in the configmap | ||
| func (ct *ConfigTracker) getDataFromConfigMap(config corev1.ConfigMap) map[string]string { | ||
| data := make(map[string]string) | ||
| maps.Copy(data, config.Data) | ||
|
|
||
| if ct.TrackBinaryData { | ||
| for k, v := range config.BinaryData { | ||
| data[k] = string(v) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. using a go playground: https://go.dev/play/p/aK0c8PId3Nv
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, I used []binary instead |
||
| } | ||
| } | ||
|
|
||
| return data | ||
| } | ||
|
|
||
| // GetTargetConfigs scans the target deployment for Kubernetes ConfigMaps and Secrets | ||
| // and returns a list of config references | ||
| func (ct *ConfigTracker) GetTargetConfigs(cd *flaggerv1.Canary) (map[string]ConfigRef, error) { | ||
|
|
@@ -334,6 +350,9 @@ func (ct *ConfigTracker) CreatePrimaryConfigs(cd *flaggerv1.Canary, refs map[str | |
| }, | ||
| Data: config.Data, | ||
| } | ||
| if ct.TrackBinaryData { | ||
| primaryConfigMap.BinaryData = config.BinaryData | ||
| } | ||
|
|
||
| // update or insert primary ConfigMap | ||
| _, err = ct.KubeClient.CoreV1().ConfigMaps(cd.Namespace).Update(context.TODO(), primaryConfigMap, metav1.UpdateOptions{}) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this needs to be exposed in the helm chart as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added