func addKeyFromLiteralToSecret(secret *api.Secret, keyName string, data []byte) error { if !validation.IsSecretKey(keyName) { return fmt.Errorf("%v is not a valid key name for a secret", keyName) } if _, entryExists := secret.Data[keyName]; entryExists { return fmt.Errorf("cannot add key %s, another key by that name already exists: %v.", keyName, secret.Data) } secret.Data[keyName] = data return nil }
// addKeyFromLiteralToConfigMap adds the given key and data to the given config map, // returning an error if the key is not valid or if the key already exists. func addKeyFromLiteralToConfigMap(configMap *api.ConfigMap, keyName, data string) error { // Note, the rules for ConfigMap keys are the exact same as the ones for SecretKeys // to be consistent; validation.IsSecretKey is used here intentionally. if !validation.IsSecretKey(keyName) { return fmt.Errorf("%v is not a valid key name for a configMap", keyName) } if _, entryExists := configMap.Data[keyName]; entryExists { return fmt.Errorf("cannot add key %s, another key by that name already exists: %v.", keyName, configMap.Data) } configMap.Data[keyName] = data return nil }