-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Add install configmap override flag #47
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
Changes from 37 commits
2fab5b7
de6acdb
ee751c2
f7066f6
3a25184
467205a
63076f2
adb8a2d
c278f49
0e975ca
d76096d
2a8ead9
95055b8
c0bd7b9
b9f54da
b208bbf
a54a8ab
449ab9e
ac0266d
f306958
0a8b117
5fa2f23
bc535f4
50a4bd1
b2ad562
d6112b0
037af32
26de1e7
8e8ce2e
83e4992
c4c1c14
922cd10
417fbc3
fcae9e6
409e6ce
f4e2fa8
eb46fab
c739946
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 |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| package util | ||
|
|
||
| import ( | ||
| "github.com/argoproj/argo-cd/common" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
|
||
| apiv1 "k8s.io/api/core/v1" | ||
| "k8s.io/client-go/kubernetes" | ||
| ) | ||
|
|
||
| // ConfigManager holds config info for a new manager with which to access Kubernetes ConfigMaps. | ||
| type ConfigManager struct { | ||
|
Collaborator
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. Right now argocd only need to read settings from config map and referenced secrets. We don't have use for create/update methods. I think ConfigManager should be responsible to deserialize Argo CD settings structure from config/secrets. E.g. now it needs only one public method GetSettings which encapsulate settings deserialization: |
||
| clientset kubernetes.Interface | ||
| } | ||
|
|
||
| // NewConfigManager generates a new ConfigManager pointer and returns it | ||
| func NewConfigManager(clientset kubernetes.Interface) (mgr *ConfigManager) { | ||
| mgr = &ConfigManager{clientset} | ||
| return | ||
| } | ||
|
|
||
| // ListConfigMaps returns a list of existing config maps. | ||
| func (mgr *ConfigManager) ListConfigMaps(namespace string) (configMaps *apiv1.ConfigMapList, err error) { | ||
| configMaps, err = mgr.clientset.CoreV1().ConfigMaps(namespace).List(metav1.ListOptions{}) | ||
| return | ||
| } | ||
|
|
||
| // CreateConfigMap stores a new config map in Kubernetes. | ||
| func (mgr *ConfigManager) CreateConfigMap(namespace, name string, value map[string]string) (configMap *apiv1.ConfigMap, err error) { | ||
| newConfigMap := &apiv1.ConfigMap{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: name, | ||
| }, | ||
| Data: value, | ||
| } | ||
| configMap, err = mgr.clientset.CoreV1().ConfigMaps(namespace).Create(newConfigMap) | ||
| return | ||
| } | ||
|
|
||
| // ReadConfigMap retrieves a config map from Kubernetes. | ||
| func (mgr *ConfigManager) ReadConfigMap(namespace, name string) (configMap *apiv1.ConfigMap, err error) { | ||
| configMap, err = mgr.clientset.CoreV1().ConfigMaps(namespace).Get(name, metav1.GetOptions{}) | ||
| return | ||
| } | ||
|
|
||
| // UpdateConfigMap overwrite-updates an existing config map in Kubernetes. This overwrite is in contrast to the merge-update done for secrets. | ||
| func (mgr *ConfigManager) UpdateConfigMap(namespace, name string, value map[string]string) (configMap *apiv1.ConfigMap, err error) { | ||
| existingConfigMap, err := mgr.ReadConfigMap(namespace, name) | ||
| if err == nil { | ||
| existingConfigMap.Data = value | ||
| configMap, err = mgr.clientset.CoreV1().ConfigMaps(namespace).Update(existingConfigMap) | ||
| } | ||
| return | ||
| } | ||
|
|
||
| // DeleteConfigMap removes a config map from Kubernetes. | ||
| func (mgr *ConfigManager) DeleteConfigMap(namespace, name string) (err error) { | ||
| err = mgr.clientset.CoreV1().ConfigMaps(namespace).Delete(name, &metav1.DeleteOptions{}) | ||
| return | ||
| } | ||
|
|
||
| // ListSecrets returns a list of existing config maps. | ||
| func (mgr *ConfigManager) ListSecrets(namespace string) (secrets *apiv1.SecretList, err error) { | ||
| secrets, err = mgr.clientset.CoreV1().Secrets(namespace).List(metav1.ListOptions{}) | ||
| return | ||
| } | ||
|
|
||
| // CreateSecret stores a new secret in Kubernetes. Set secretType to "" for no label. | ||
| func (mgr *ConfigManager) CreateSecret(namespace, name string, value map[string]string, secretType string) (secret *apiv1.Secret, err error) { | ||
| labels := make(map[string]string) | ||
| if secretType != "" { | ||
| labels[common.LabelKeySecretType] = secretType | ||
| } | ||
| newSecret := &apiv1.Secret{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: name, | ||
| Labels: labels, | ||
| }, | ||
| } | ||
| newSecret.StringData = value | ||
| secret, err = mgr.clientset.CoreV1().Secrets(namespace).Create(newSecret) | ||
| return | ||
| } | ||
|
|
||
| // Read retrieves a secret from Kubernetes. | ||
| func (mgr *ConfigManager) ReadSecret(namespace, name string) (secret *apiv1.Secret, err error) { | ||
| secret, err = mgr.clientset.CoreV1().Secrets(namespace).Get(name, metav1.GetOptions{}) | ||
| return | ||
| } | ||
|
|
||
| // UpdateSecret merge-updates an existing secret in Kubernetes. This merge-update is in contrast to the overwrite-update done for config maps. | ||
| func (mgr *ConfigManager) UpdateSecret(namespace, name string, value map[string]string) (secret *apiv1.Secret, err error) { | ||
| existingSecret, err := mgr.ReadSecret(namespace, name) | ||
| if err == nil { | ||
| existingSecret.StringData = value | ||
| secret, err = mgr.clientset.CoreV1().Secrets(namespace).Update(existingSecret) | ||
| } | ||
| return | ||
| } | ||
|
|
||
| // DeleteSecret removes a secret from Kubernetes. | ||
| func (mgr *ConfigManager) DeleteSecret(namespace, name string) (err error) { | ||
| err = mgr.clientset.CoreV1().Secrets(namespace).Delete(name, &metav1.DeleteOptions{}) | ||
| return | ||
| } | ||
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.
As we discussed we will need to add more hardcoded parameters into settings structure (e.g. app resync timeout). These parameters are not specific to argocd server, so I would suggest to move settings struct definition into util package next to config manager