create or update secrets

This commit is contained in:
GLYASAI 2020-10-09 10:18:13 +08:00
parent 11b638273d
commit f0616b9e86
2 changed files with 24 additions and 0 deletions

View File

@ -222,6 +222,12 @@ func (s *upgradeController) upgradeOne(app v1.AppService) error {
} }
_ = f.UpgradeSecrets(s.manager.client, &app, oldApp.GetSecrets(true), app.GetSecrets(true), handleErr) _ = f.UpgradeSecrets(s.manager.client, &app, oldApp.GetSecrets(true), app.GetSecrets(true), handleErr)
_ = f.UpgradeIngress(s.manager.client, &app, oldApp.GetIngress(true), app.GetIngress(true), handleErr) _ = f.UpgradeIngress(s.manager.client, &app, oldApp.GetIngress(true), app.GetIngress(true), handleErr)
for _, secret := range app.GetEnvVarSecrets(true) {
err := f.CreateOrUpdateSecret(s.manager.client, secret)
if err != nil {
return fmt.Errorf("[upgradeController] [upgradeOne] create or update secrets: %v", err)
}
}
if crd, _ := s.manager.store.GetCrd(store.ServiceMonitor); crd != nil { if crd, _ := s.manager.store.GetCrd(store.ServiceMonitor); crd != nil {
client, err := s.manager.store.GetServiceMonitorClient() client, err := s.manager.store.GetServiceMonitorClient()

View File

@ -579,3 +579,21 @@ func UpgradeServiceMonitor(
} }
return nil return nil
} }
// CreateOrUpdateSecret creates or updates secret.
func CreateOrUpdateSecret(clientset kubernetes.Interface, secret *corev1.Secret) error {
old, err := clientset.CoreV1().Secrets(secret.Namespace).Get(secret.Name, metav1.GetOptions{})
if err != nil {
if !k8sErrors.IsNotFound(err) {
return err
}
// create secret
_, err := clientset.CoreV1().Secrets(secret.Namespace).Create(secret)
return err
}
// update secret
secret.ResourceVersion = old.ResourceVersion
_, err = clientset.CoreV1().Secrets(secret.Namespace).Update(secret)
return err
}