MCPcopy
hub / github.com/kubeedge/kubeedge / SaveSecret

Function SaveSecret

cloud/pkg/common/client/secret.go:34–49  ·  view source on GitHub ↗

saveSecret creates a secret when it does not exist, otherwise updates it.

(ctx context.Context, secret *corev1.Secret, ns string)

Source from the content-addressed store, hash-verified

32
33// saveSecret creates a secret when it does not exist, otherwise updates it.
34func SaveSecret(ctx context.Context, secret *corev1.Secret, ns string) error {
35 cli := GetKubeClient()
36 if err := CreateNamespaceIfNeeded(ctx, ns); err != nil {
37 return fmt.Errorf("failed to create Namespace kubeedge, error: %v", err)
38 }
39 if _, err := cli.CoreV1().Secrets(ns).Create(ctx, secret, metav1.CreateOptions{}); err != nil {
40 if errors.IsAlreadyExists(err) {
41 if _, err := cli.CoreV1().Secrets(ns).Update(ctx, secret, metav1.UpdateOptions{}); err != nil {
42 return fmt.Errorf("failed to update the secret, namespace: %s, name: %s, err: %v", ns, secret.Name, err)
43 }
44 } else {
45 return fmt.Errorf("failed to create the secret, namespace: %s, name: %s, err: %v", ns, secret.Name, err)
46 }
47 }
48 return nil
49}

Callers 4

createCAToSecretFunction · 0.92
createCertsToSecretFunction · 0.92
createNewTokenFunction · 0.92
TestSaveSecretFunction · 0.85

Calls 6

GetKubeClientFunction · 0.85
CreateNamespaceIfNeededFunction · 0.85
CoreV1Method · 0.80
CreateMethod · 0.65
SecretsMethod · 0.65
UpdateMethod · 0.65

Tested by 1

TestSaveSecretFunction · 0.68