mirror of
https://gitee.com/rainbond/Rainbond.git
synced 2024-12-02 11:47:36 +08:00
create or update secrets
This commit is contained in:
parent
11b638273d
commit
f0616b9e86
@ -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.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 {
|
||||
client, err := s.manager.store.GetServiceMonitorClient()
|
||||
|
@ -579,3 +579,21 @@ func UpgradeServiceMonitor(
|
||||
}
|
||||
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user