mirror of
				https://github.com/1Password/onepassword-operator.git
				synced 2025-10-31 11:49:40 +00:00 
			
		
		
		
	Compare commits
	
		
			20 Commits
		
	
	
		
			update-pat
			...
			v1.1.0
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | d807e92c36 | ||
|   | 244771717c | ||
|   | 7aeb36e383 | ||
|   | 5c2f840623 | ||
|   | 670040477e | ||
|   | a45a310611 | ||
|   | d80e8dd799 | ||
|   | 88728909ff | ||
|   | e365ebfdfa | ||
|   | 2c4b4df01a | ||
|   | 0193a98681 | ||
|   | f241d7423d | ||
|   | c0037526b0 | ||
|   | dff934cbc3 | ||
|   | 2096f4440f | ||
|   | b3fc707337 | ||
|   | fb1262f1bd | ||
|   | a428fe7462 | ||
|   | ea2d1f8a09 | ||
|   | bd96d50a9b | 
| @@ -12,6 +12,14 @@ | ||||
|  | ||||
| --- | ||||
|  | ||||
| [//]: # (START/v1.1.0) | ||||
| # v1.1.0 | ||||
|  | ||||
| ## Fixes | ||||
|  * Fix normalization for keys in a Secret's `data` section to allow upper- and lower-case alphanumeric characters. {#66} | ||||
|  | ||||
| --- | ||||
|  | ||||
| [//]: # (START/v1.0.2) | ||||
| # v1.0.2 | ||||
|  | ||||
|   | ||||
							
								
								
									
										12
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								README.md
									
									
									
									
									
								
							| @@ -2,7 +2,7 @@ | ||||
|  | ||||
| The 1Password Connect Kubernetes Operator provides the ability to integrate Kubernetes with 1Password. This Operator manages `OnePasswordItem` Custom Resource Definitions (CRDs) that define the location of an Item stored in 1Password. The `OnePasswordItem` CRD, when created, will be used to compose a Kubernetes Secret containing the contents of the specified item. | ||||
|  | ||||
| The 1Password Connect Kubernetes Operator also allows for Kubernetes Secrets to be composed from a 1Password Item through annotation of an Item Reference on a deployment. | ||||
| The 1Password Connect Kubernetes Operator also allows for Kubernetes Secrets to be composed from a 1Password Item through annotation of an Item Path on a deployment. | ||||
|  | ||||
| The 1Password Connect Kubernetes Operator will continually check for updates from 1Password for any Kubernetes Secret that it has generated. If a Kubernetes Secret is updated, any Deployment using that secret can be automatically restarted. | ||||
|  | ||||
| @@ -106,7 +106,7 @@ kind: OnePasswordItem | ||||
| metadata: | ||||
|   name: <item_name> #this name will also be used for naming the generated kubernetes secret | ||||
| spec: | ||||
|   itemReference: "op://<vault_id_or_title>/<item_id_or_title>"  | ||||
|   itemPath: "vaults/<vault_id_or_title>/items/<item_id_or_title>"  | ||||
| ``` | ||||
|  | ||||
| Deploy the OnePasswordItem to Kubernetes: | ||||
| @@ -131,20 +131,20 @@ kind: Deployment | ||||
| metadata: | ||||
|   name: deployment-example | ||||
|   annotations: | ||||
|     operator.1password.io/item-reference: "op://<vault>/<item>" | ||||
|     operator.1password.io/item-path: "vaults/<vault_id_or_title>/items/<item_id_or_title>" | ||||
|     operator.1password.io/item-name: "<secret_name>" | ||||
| ``` | ||||
|  | ||||
| Applying this yaml file will create a Kubernetes Secret with the name `<secret_name>` and contents from the location specified at the specified Item Reference. | ||||
| Applying this yaml file will create a Kubernetes Secret with the name `<secret_name>` and contents from the location specified at the specified Item Path. | ||||
|  | ||||
| Note: Deleting the Deployment that you've created will automatically delete the created Kubernetes Secret only if the deployment is still annotated with `operator.1password.io/item-reference` and `operator.1password.io/item-name` and no other deployment is using the secret. | ||||
| Note: Deleting the Deployment that you've created will automatically delete the created Kubernetes Secret only if the deployment is still annotated with `operator.1password.io/item-path` and `operator.1password.io/item-name` and no other deployment is using the secret. | ||||
|  | ||||
| If a 1Password Item that is linked to a Kubernetes Secret is updated within the POLLING_INTERVAL the associated Kubernetes Secret will be updated. However, if you do not want a specific secret to be updated you can add the tag `operator.1password.io:ignore-secret` to the item stored in 1Password. While this tag is in place, any updates made to an item will not trigger an update to the associated secret in Kubernetes. | ||||
|  | ||||
| --- | ||||
| **NOTE** | ||||
|  | ||||
| If multiple 1Password vaults/items have the same `title` when using a title in the access reference, the desired action will be performed on the oldest vault/item.  | ||||
| If multiple 1Password vaults/items have the same `title` when using a title in the access path, the desired action will be performed on the oldest vault/item.  | ||||
|  | ||||
| Titles and field names that include white space and other characters that are not a valid [DNS subdomain name](https://kubernetes.io/docs/concepts/configuration/secret/) will create Kubernetes secrets that have titles and fields in the following format: | ||||
|  - Invalid characters before the first alphanumeric character and after the last alphanumeric character will be removed | ||||
|   | ||||
| @@ -178,8 +178,7 @@ func main() { | ||||
| 				ticker.Stop() | ||||
| 				return | ||||
| 			case <-ticker.C: | ||||
| 				err := updatedSecretsPoller.UpdateKubernetesSecretsTask() | ||||
| 				log.Error(err, "Error occured during update secret task") | ||||
| 				updatedSecretsPoller.UpdateKubernetesSecretsTask() | ||||
| 			} | ||||
| 		} | ||||
| 	}() | ||||
|   | ||||
| @@ -33,7 +33,7 @@ spec: | ||||
|           spec: | ||||
|             description: OnePasswordItemSpec defines the desired state of OnePasswordItem | ||||
|             properties: | ||||
|               itemReference: | ||||
|               itemPath: | ||||
|                 type: string | ||||
|             type: object | ||||
|           status: | ||||
|   | ||||
| @@ -3,4 +3,4 @@ kind: OnePasswordItem | ||||
| metadata: | ||||
|   name: example | ||||
| spec: | ||||
|   itemReference: "op://<vault_id>/<item_id>" | ||||
|   itemPath: "vaults/<vault_id>/items/<item_id>" | ||||
|   | ||||
| @@ -16,7 +16,6 @@ spec: | ||||
|       containers: | ||||
|         - name: onepassword-connect-operator | ||||
|           image: 1password/onepassword-operator | ||||
|           imagePullPolicy: Never | ||||
|           command: ["/manager"] | ||||
|           env: | ||||
|             - name: WATCH_NAMESPACE | ||||
|   | ||||
| @@ -8,7 +8,7 @@ import ( | ||||
|  | ||||
| // OnePasswordItemSpec defines the desired state of OnePasswordItem | ||||
| type OnePasswordItemSpec struct { | ||||
| 	ItemReference string `json:"itemReference,omitempty"` | ||||
| 	ItemPath string `json:"itemPath,omitempty"` | ||||
| } | ||||
|  | ||||
| // OnePasswordItemStatus defines the observed state of OnePasswordItem | ||||
|   | ||||
| @@ -191,15 +191,16 @@ func (r *ReconcileDeployment) HandleApplyingDeployment(namespace string, annotat | ||||
| 	reqLog := log.WithValues("Request.Namespace", request.Namespace, "Request.Name", request.Name) | ||||
|  | ||||
| 	secretName := annotations[op.NameAnnotation] | ||||
| 	secretLabels := map[string]string(nil) | ||||
| 	if len(secretName) == 0 { | ||||
| 		reqLog.Info("No 'item-name' annotation set. 'item-reference' and 'item-name' must be set as annotations to add new secret.") | ||||
| 		reqLog.Info("No 'item-name' annotation set. 'item-path' and 'item-name' must be set as annotations to add new secret.") | ||||
| 		return nil | ||||
| 	} | ||||
|  | ||||
| 	item, err := op.GetOnePasswordItemByReference(r.opConnectClient, annotations[op.ItemReferenceAnnotation]) | ||||
| 	item, err := op.GetOnePasswordItemByPath(r.opConnectClient, annotations[op.ItemPathAnnotation]) | ||||
| 	if err != nil { | ||||
| 		return fmt.Errorf("Failed to retrieve item: %v", err) | ||||
| 	} | ||||
|  | ||||
| 	return kubeSecrets.CreateKubernetesSecretFromItem(r.kubeClient, secretName, namespace, item, annotations[op.RestartDeploymentsAnnotation]) | ||||
| 	return kubeSecrets.CreateKubernetesSecretFromItem(r.kubeClient, secretName, namespace, item, annotations[op.RestartDeploymentsAnnotation], secretLabels, annotations) | ||||
| } | ||||
|   | ||||
| @@ -52,7 +52,7 @@ var ( | ||||
| 		"password": []byte(password), | ||||
| 		"username": []byte(username), | ||||
| 	} | ||||
| 	ItemReference = fmt.Sprintf("op://%v/%v", vaultId, itemId) | ||||
| 	itemPath = fmt.Sprintf("vaults/%v/items/%v", vaultId, itemId) | ||||
| ) | ||||
|  | ||||
| var ( | ||||
| @@ -76,8 +76,8 @@ var tests = []testReconcileItem{ | ||||
| 					finalizer, | ||||
| 				}, | ||||
| 				Annotations: map[string]string{ | ||||
| 					op.ItemReferenceAnnotation: ItemReference, | ||||
| 					op.NameAnnotation:          name, | ||||
| 					op.ItemPathAnnotation: itemPath, | ||||
| 					op.NameAnnotation:     name, | ||||
| 				}, | ||||
| 			}, | ||||
| 		}, | ||||
| @@ -90,8 +90,8 @@ var tests = []testReconcileItem{ | ||||
| 				Name:      "another-deployment", | ||||
| 				Namespace: namespace, | ||||
| 				Annotations: map[string]string{ | ||||
| 					op.ItemReferenceAnnotation: ItemReference, | ||||
| 					op.NameAnnotation:          name, | ||||
| 					op.ItemPathAnnotation: itemPath, | ||||
| 					op.NameAnnotation:     name, | ||||
| 				}, | ||||
| 			}, | ||||
| 			Spec: appsv1.DeploymentSpec{ | ||||
| @@ -152,8 +152,8 @@ var tests = []testReconcileItem{ | ||||
| 					finalizer, | ||||
| 				}, | ||||
| 				Annotations: map[string]string{ | ||||
| 					op.ItemReferenceAnnotation: ItemReference, | ||||
| 					op.NameAnnotation:          name, | ||||
| 					op.ItemPathAnnotation: itemPath, | ||||
| 					op.NameAnnotation:     name, | ||||
| 				}, | ||||
| 			}, | ||||
| 		}, | ||||
| @@ -166,8 +166,8 @@ var tests = []testReconcileItem{ | ||||
| 				Name:      "another-deployment", | ||||
| 				Namespace: namespace, | ||||
| 				Annotations: map[string]string{ | ||||
| 					op.ItemReferenceAnnotation: ItemReference, | ||||
| 					op.NameAnnotation:          name, | ||||
| 					op.ItemPathAnnotation: itemPath, | ||||
| 					op.NameAnnotation:     name, | ||||
| 				}, | ||||
| 			}, | ||||
| 			Spec: appsv1.DeploymentSpec{ | ||||
| @@ -235,8 +235,8 @@ var tests = []testReconcileItem{ | ||||
| 					finalizer, | ||||
| 				}, | ||||
| 				Annotations: map[string]string{ | ||||
| 					op.ItemReferenceAnnotation: ItemReference, | ||||
| 					op.NameAnnotation:          name, | ||||
| 					op.ItemPathAnnotation: itemPath, | ||||
| 					op.NameAnnotation:     name, | ||||
| 				}, | ||||
| 			}, | ||||
| 		}, | ||||
| @@ -258,7 +258,7 @@ var tests = []testReconcileItem{ | ||||
| 		}, | ||||
| 	}, | ||||
| 	{ | ||||
| 		testName: "Test Do not update if OnePassword Item Version has not changed", | ||||
| 		testName: "Test Do not update if Annotations have not changed", | ||||
| 		deploymentResource: &appsv1.Deployment{ | ||||
| 			TypeMeta: metav1.TypeMeta{ | ||||
| 				Kind:       deploymentKind, | ||||
| @@ -268,9 +268,10 @@ var tests = []testReconcileItem{ | ||||
| 				Name:      name, | ||||
| 				Namespace: namespace, | ||||
| 				Annotations: map[string]string{ | ||||
| 					op.ItemReferenceAnnotation: ItemReference, | ||||
| 					op.NameAnnotation:          name, | ||||
| 					op.ItemPathAnnotation: itemPath, | ||||
| 					op.NameAnnotation:     name, | ||||
| 				}, | ||||
| 				Labels: map[string]string{}, | ||||
| 			}, | ||||
| 		}, | ||||
| 		existingSecret: &corev1.Secret{ | ||||
| @@ -279,6 +280,8 @@ var tests = []testReconcileItem{ | ||||
| 				Namespace: namespace, | ||||
| 				Annotations: map[string]string{ | ||||
| 					op.VersionAnnotation: fmt.Sprint(version), | ||||
| 					op.ItemPathAnnotation: itemPath, | ||||
| 					op.NameAnnotation:     name, | ||||
| 				}, | ||||
| 			}, | ||||
| 			Data: expectedSecretData, | ||||
| @@ -290,7 +293,10 @@ var tests = []testReconcileItem{ | ||||
| 				Namespace: namespace, | ||||
| 				Annotations: map[string]string{ | ||||
| 					op.VersionAnnotation: fmt.Sprint(version), | ||||
| 					op.ItemPathAnnotation: itemPath, | ||||
| 					op.NameAnnotation:     name, | ||||
| 				}, | ||||
| 				Labels: map[string]string(nil), | ||||
| 			}, | ||||
| 			Data: expectedSecretData, | ||||
| 		}, | ||||
| @@ -310,8 +316,8 @@ var tests = []testReconcileItem{ | ||||
| 				Name:      name, | ||||
| 				Namespace: namespace, | ||||
| 				Annotations: map[string]string{ | ||||
| 					op.ItemReferenceAnnotation: ItemReference, | ||||
| 					op.NameAnnotation:          name, | ||||
| 					op.ItemPathAnnotation: itemPath, | ||||
| 					op.NameAnnotation:     name, | ||||
| 				}, | ||||
| 			}, | ||||
| 		}, | ||||
| @@ -352,8 +358,8 @@ var tests = []testReconcileItem{ | ||||
| 				Name:      name, | ||||
| 				Namespace: namespace, | ||||
| 				Annotations: map[string]string{ | ||||
| 					op.ItemReferenceAnnotation: ItemReference, | ||||
| 					op.NameAnnotation:          name, | ||||
| 					op.ItemPathAnnotation: itemPath, | ||||
| 					op.NameAnnotation:     name, | ||||
| 				}, | ||||
| 			}, | ||||
| 		}, | ||||
|   | ||||
| @@ -3,7 +3,6 @@ package onepassworditem | ||||
| import ( | ||||
| 	"context" | ||||
| 	"fmt" | ||||
|  | ||||
| 	onepasswordv1 "github.com/1Password/onepassword-operator/pkg/apis/onepassword/v1" | ||||
| 	kubeSecrets "github.com/1Password/onepassword-operator/pkg/kubernetessecrets" | ||||
| 	"github.com/1Password/onepassword-operator/pkg/onepassword" | ||||
| @@ -144,12 +143,14 @@ func (r *ReconcileOnePasswordItem) removeOnePasswordFinalizerFromOnePasswordItem | ||||
|  | ||||
| func (r *ReconcileOnePasswordItem) HandleOnePasswordItem(resource *onepasswordv1.OnePasswordItem, request reconcile.Request) error { | ||||
| 	secretName := resource.GetName() | ||||
| 	autoRestart := resource.Annotations[op.RestartDeploymentsAnnotation] | ||||
| 	labels := resource.Labels | ||||
| 	annotations := resource.Annotations | ||||
| 	autoRestart := annotations[op.RestartDeploymentsAnnotation] | ||||
|  | ||||
| 	item, err := onepassword.GetOnePasswordItemByReference(r.opConnectClient, resource.Spec.ItemReference) | ||||
| 	item, err := onepassword.GetOnePasswordItemByPath(r.opConnectClient, resource.Spec.ItemPath) | ||||
| 	if err != nil { | ||||
| 		return fmt.Errorf("Failed to retrieve item: %v", err) | ||||
| 	} | ||||
|  | ||||
| 	return kubeSecrets.CreateKubernetesSecretFromItem(r.kubeClient, secretName, resource.Namespace, item, autoRestart) | ||||
| 	return kubeSecrets.CreateKubernetesSecretFromItem(r.kubeClient, secretName, resource.Namespace, item, autoRestart, labels, annotations) | ||||
| } | ||||
|   | ||||
| @@ -55,7 +55,7 @@ var ( | ||||
| 		"password": []byte(password), | ||||
| 		"username": []byte(username), | ||||
| 	} | ||||
| 	itemReference = fmt.Sprintf("op://%v/%v", vaultId, itemId) | ||||
| 	itemPath = fmt.Sprintf("vaults/%v/items/%v", vaultId, itemId) | ||||
| ) | ||||
|  | ||||
| var ( | ||||
| @@ -79,7 +79,7 @@ var tests = []testReconcileItem{ | ||||
| 				}, | ||||
| 			}, | ||||
| 			Spec: onepasswordv1.OnePasswordItemSpec{ | ||||
| 				ItemReference: itemReference, | ||||
| 				ItemPath: itemPath, | ||||
| 			}, | ||||
| 		}, | ||||
| 		existingSecret: &corev1.Secret{ | ||||
| @@ -111,7 +111,7 @@ var tests = []testReconcileItem{ | ||||
| 				Namespace: namespace, | ||||
| 			}, | ||||
| 			Spec: onepasswordv1.OnePasswordItemSpec{ | ||||
| 				ItemReference: itemReference, | ||||
| 				ItemPath: itemPath, | ||||
| 			}, | ||||
| 		}, | ||||
| 		existingSecret: &corev1.Secret{ | ||||
| @@ -120,6 +120,7 @@ var tests = []testReconcileItem{ | ||||
| 				Namespace: namespace, | ||||
| 				Annotations: map[string]string{ | ||||
| 					op.VersionAnnotation: fmt.Sprint(version), | ||||
| 					op.ItemPathAnnotation: itemPath, | ||||
| 				}, | ||||
| 			}, | ||||
| 			Data: expectedSecretData, | ||||
| @@ -131,6 +132,7 @@ var tests = []testReconcileItem{ | ||||
| 				Namespace: namespace, | ||||
| 				Annotations: map[string]string{ | ||||
| 					op.VersionAnnotation: fmt.Sprint(version), | ||||
| 					op.ItemPathAnnotation: itemPath, | ||||
| 				}, | ||||
| 			}, | ||||
| 			Data: expectedSecretData, | ||||
| @@ -150,9 +152,14 @@ var tests = []testReconcileItem{ | ||||
| 			ObjectMeta: metav1.ObjectMeta{ | ||||
| 				Name:      name, | ||||
| 				Namespace: namespace, | ||||
| 				Annotations: map[string]string{ | ||||
| 					op.VersionAnnotation: fmt.Sprint(version), | ||||
| 					op.ItemPathAnnotation: itemPath, | ||||
| 				}, | ||||
| 				Labels: map[string]string{}, | ||||
| 			}, | ||||
| 			Spec: onepasswordv1.OnePasswordItemSpec{ | ||||
| 				ItemReference: itemReference, | ||||
| 				ItemPath: itemPath, | ||||
| 			}, | ||||
| 		}, | ||||
| 		existingSecret: &corev1.Secret{ | ||||
| @@ -161,7 +168,9 @@ var tests = []testReconcileItem{ | ||||
| 				Namespace: namespace, | ||||
| 				Annotations: map[string]string{ | ||||
| 					op.VersionAnnotation: "456", | ||||
| 					op.ItemPathAnnotation: itemPath, | ||||
| 				}, | ||||
| 				Labels: map[string]string{}, | ||||
| 			}, | ||||
| 			Data: expectedSecretData, | ||||
| 		}, | ||||
| @@ -172,7 +181,9 @@ var tests = []testReconcileItem{ | ||||
| 				Namespace: namespace, | ||||
| 				Annotations: map[string]string{ | ||||
| 					op.VersionAnnotation: fmt.Sprint(version), | ||||
| 					op.ItemPathAnnotation: itemPath, | ||||
| 				}, | ||||
| 				Labels: map[string]string{}, | ||||
| 			}, | ||||
| 			Data: expectedSecretData, | ||||
| 		}, | ||||
| @@ -193,7 +204,7 @@ var tests = []testReconcileItem{ | ||||
| 				Namespace: namespace, | ||||
| 			}, | ||||
| 			Spec: onepasswordv1.OnePasswordItemSpec{ | ||||
| 				ItemReference: itemReference, | ||||
| 				ItemPath: itemPath, | ||||
| 			}, | ||||
| 		}, | ||||
| 		existingSecret: nil, | ||||
| @@ -225,7 +236,7 @@ var tests = []testReconcileItem{ | ||||
| 				Namespace: namespace, | ||||
| 			}, | ||||
| 			Spec: onepasswordv1.OnePasswordItemSpec{ | ||||
| 				ItemReference: itemReference, | ||||
| 				ItemPath: itemPath, | ||||
| 			}, | ||||
| 		}, | ||||
| 		existingSecret: nil, | ||||
| @@ -257,7 +268,7 @@ var tests = []testReconcileItem{ | ||||
| 				Namespace: namespace, | ||||
| 			}, | ||||
| 			Spec: onepasswordv1.OnePasswordItemSpec{ | ||||
| 				ItemReference: itemReference, | ||||
| 				ItemPath: itemPath, | ||||
| 			}, | ||||
| 		}, | ||||
| 		existingSecret: nil, | ||||
| @@ -274,7 +285,7 @@ var tests = []testReconcileItem{ | ||||
| 				"password":       []byte(password), | ||||
| 				"username":       []byte(username), | ||||
| 				"first-host":     []byte(firstHost), | ||||
| 				"aws-access-key": []byte(awsKey), | ||||
| 				"AWS-Access-Key": []byte(awsKey), | ||||
| 				"ice-cream-type": []byte(iceCream), | ||||
| 			}, | ||||
| 		}, | ||||
| @@ -286,6 +297,47 @@ var tests = []testReconcileItem{ | ||||
| 			"😄 ice-cream type": iceCream, | ||||
| 		}, | ||||
| 	}, | ||||
| 	{ | ||||
| 		testName: "Secret from 1Password item with `-`, `_` and `.`", | ||||
| 		customResource: &onepasswordv1.OnePasswordItem{ | ||||
| 			TypeMeta: metav1.TypeMeta{ | ||||
| 				Kind:       onePasswordItemKind, | ||||
| 				APIVersion: onePasswordItemAPIVersion, | ||||
| 			}, | ||||
| 			ObjectMeta: metav1.ObjectMeta{ | ||||
| 				Name:      "!.my_sECReT.it3m%-_", | ||||
| 				Namespace: namespace, | ||||
| 			}, | ||||
| 			Spec: onepasswordv1.OnePasswordItemSpec{ | ||||
| 				ItemPath: itemPath, | ||||
| 			}, | ||||
| 		}, | ||||
| 		existingSecret: nil, | ||||
| 		expectedError:  nil, | ||||
| 		expectedResultSecret: &corev1.Secret{ | ||||
| 			ObjectMeta: metav1.ObjectMeta{ | ||||
| 				Name:      "my-secret.it3m", | ||||
| 				Namespace: namespace, | ||||
| 				Annotations: map[string]string{ | ||||
| 					op.VersionAnnotation: fmt.Sprint(version), | ||||
| 				}, | ||||
| 			}, | ||||
| 			Data: map[string][]byte{ | ||||
| 				"password":          []byte(password), | ||||
| 				"username":          []byte(username), | ||||
| 				"first-host":        []byte(firstHost), | ||||
| 				"AWS-Access-Key":    []byte(awsKey), | ||||
| 				"-_ice_cream.type.": []byte(iceCream), | ||||
| 			}, | ||||
| 		}, | ||||
| 		opItem: map[string]string{ | ||||
| 			userKey:               username, | ||||
| 			passKey:               password, | ||||
| 			"first host":          firstHost, | ||||
| 			"AWS Access Key":      awsKey, | ||||
| 			"😄 -_ice_cream.type.": iceCream, | ||||
| 		}, | ||||
| 	}, | ||||
| } | ||||
|  | ||||
| func TestReconcileOnePasswordItem(t *testing.T) { | ||||
|   | ||||
| @@ -13,6 +13,7 @@ import ( | ||||
| 	"k8s.io/apimachinery/pkg/api/errors" | ||||
| 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||||
| 	"k8s.io/apimachinery/pkg/types" | ||||
| 	"reflect" | ||||
| 	kubeValidate "k8s.io/apimachinery/pkg/util/validation" | ||||
|  | ||||
| 	kubernetesClient "sigs.k8s.io/controller-runtime/pkg/client" | ||||
| @@ -23,27 +24,32 @@ const OnepasswordPrefix = "operator.1password.io" | ||||
| const NameAnnotation = OnepasswordPrefix + "/item-name" | ||||
| const VersionAnnotation = OnepasswordPrefix + "/item-version" | ||||
| const restartAnnotation = OnepasswordPrefix + "/last-restarted" | ||||
| const ItemReferenceAnnotation = OnepasswordPrefix + "/item-reference" | ||||
| const ItemPathAnnotation = OnepasswordPrefix + "/item-path" | ||||
| const RestartDeploymentsAnnotation = OnepasswordPrefix + "/auto-restart" | ||||
|  | ||||
| var log = logf.Log | ||||
|  | ||||
| func CreateKubernetesSecretFromItem(kubeClient kubernetesClient.Client, secretName, namespace string, item *onepassword.Item, autoRestart string) error { | ||||
| func CreateKubernetesSecretFromItem(kubeClient kubernetesClient.Client, secretName, namespace string, item *onepassword.Item, autoRestart string, labels map[string]string, secretAnnotations map[string]string) error { | ||||
|  | ||||
| 	itemVersion := fmt.Sprint(item.Version) | ||||
| 	annotations := map[string]string{ | ||||
| 		VersionAnnotation:       itemVersion, | ||||
| 		ItemReferenceAnnotation: fmt.Sprintf("op://%v/%v", item.Vault.ID, item.ID), | ||||
|  | ||||
| 	// If secretAnnotations is nil we create an empty map so we can later assign values for the OP Annotations in the map | ||||
| 	if secretAnnotations == nil { | ||||
| 		secretAnnotations = map[string]string{} | ||||
| 	} | ||||
|  | ||||
| 	secretAnnotations[VersionAnnotation] = itemVersion | ||||
| 	secretAnnotations[ItemPathAnnotation] = fmt.Sprintf("vaults/%v/items/%v", item.Vault.ID, item.ID) | ||||
|  | ||||
| 	if autoRestart != "" { | ||||
| 		_, err := utils.StringToBool(autoRestart) | ||||
| 		if err != nil { | ||||
| 			log.Error(err, "Error parsing %v annotation on Secret %v. Must be true or false. Defaulting to false.", RestartDeploymentsAnnotation, secretName) | ||||
| 			return err | ||||
| 		} | ||||
| 		annotations[RestartDeploymentsAnnotation] = autoRestart | ||||
| 		secretAnnotations[RestartDeploymentsAnnotation] = autoRestart | ||||
| 	} | ||||
| 	secret := BuildKubernetesSecretFromOnePasswordItem(secretName, namespace, annotations, *item) | ||||
| 	secret := BuildKubernetesSecretFromOnePasswordItem(secretName, namespace, secretAnnotations, labels, *item) | ||||
|  | ||||
| 	currentSecret := &corev1.Secret{} | ||||
| 	err := kubeClient.Get(context.Background(), types.NamespacedName{Name: secret.Name, Namespace: secret.Namespace}, currentSecret) | ||||
| @@ -54,9 +60,10 @@ func CreateKubernetesSecretFromItem(kubeClient kubernetesClient.Client, secretNa | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	if currentSecret.Annotations[VersionAnnotation] != itemVersion { | ||||
| 	if ! reflect.DeepEqual(currentSecret.Annotations, secretAnnotations) || ! reflect.DeepEqual(currentSecret.Labels, labels) { | ||||
| 		log.Info(fmt.Sprintf("Updating Secret %v at namespace '%v'", secret.Name, secret.Namespace)) | ||||
| 		currentSecret.ObjectMeta.Annotations = annotations | ||||
| 		currentSecret.ObjectMeta.Annotations = secretAnnotations | ||||
| 		currentSecret.ObjectMeta.Labels = labels | ||||
| 		currentSecret.Data = secret.Data | ||||
| 		return kubeClient.Update(context.Background(), currentSecret) | ||||
| 	} | ||||
| @@ -65,12 +72,13 @@ func CreateKubernetesSecretFromItem(kubeClient kubernetesClient.Client, secretNa | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func BuildKubernetesSecretFromOnePasswordItem(name, namespace string, annotations map[string]string, item onepassword.Item) *corev1.Secret { | ||||
| func BuildKubernetesSecretFromOnePasswordItem(name, namespace string, annotations map[string]string, labels map[string]string, item onepassword.Item) *corev1.Secret { | ||||
| 	return &corev1.Secret{ | ||||
| 		ObjectMeta: metav1.ObjectMeta{ | ||||
| 			Name:        formatSecretName(name), | ||||
| 			Namespace:   namespace, | ||||
| 			Annotations: annotations, | ||||
| 			Labels:      labels, | ||||
| 		}, | ||||
| 		Data: BuildKubernetesSecretData(item.Fields), | ||||
| 	} | ||||
| @@ -80,16 +88,17 @@ func BuildKubernetesSecretData(fields []*onepassword.ItemField) map[string][]byt | ||||
| 	secretData := map[string][]byte{} | ||||
| 	for i := 0; i < len(fields); i++ { | ||||
| 		if fields[i].Value != "" { | ||||
| 			key := formatSecretName(fields[i].Label) | ||||
| 			key := formatSecretDataName(fields[i].Label) | ||||
| 			secretData[key] = []byte(fields[i].Value) | ||||
| 		} | ||||
| 	} | ||||
| 	return secretData | ||||
| } | ||||
|  | ||||
| // formatSecretName rewrites a value to be a valid Secret name or Secret data key. | ||||
| // formatSecretName rewrites a value to be a valid Secret name. | ||||
| // | ||||
| // The Secret meta.name and data keys must be valid DNS subdomain names (https://kubernetes.io/docs/concepts/configuration/secret/#overview-of-secrets) | ||||
| // The Secret meta.name and data keys must be valid DNS subdomain names | ||||
| // (https://kubernetes.io/docs/concepts/configuration/secret/#overview-of-secrets) | ||||
| func formatSecretName(value string) string { | ||||
| 	if errs := kubeValidate.IsDNS1123Subdomain(value); len(errs) == 0 { | ||||
| 		return value | ||||
| @@ -97,7 +106,18 @@ func formatSecretName(value string) string { | ||||
| 	return createValidSecretName(value) | ||||
| } | ||||
|  | ||||
| var invalidDNS1123Chars = regexp.MustCompile("[^a-z0-9-]+") | ||||
| // formatSecretDataName rewrites a value to be a valid Secret data key. | ||||
| // | ||||
| // The Secret data keys must consist of alphanumeric numbers, `-`, `_` or `.` | ||||
| // (https://kubernetes.io/docs/concepts/configuration/secret/#overview-of-secrets) | ||||
| func formatSecretDataName(value string) string { | ||||
| 	if errs := kubeValidate.IsConfigMapKey(value); len(errs) == 0 { | ||||
| 		return value | ||||
| 	} | ||||
| 	return createValidSecretDataName(value) | ||||
| } | ||||
|  | ||||
| var invalidDNS1123Chars = regexp.MustCompile("[^a-z0-9-.]+") | ||||
|  | ||||
| func createValidSecretName(value string) string { | ||||
| 	result := strings.ToLower(value) | ||||
| @@ -108,5 +128,19 @@ func createValidSecretName(value string) string { | ||||
| 	} | ||||
|  | ||||
| 	// first and last character MUST be alphanumeric | ||||
| 	return strings.Trim(result, "-") | ||||
| 	return strings.Trim(result, "-.") | ||||
| } | ||||
|  | ||||
| var invalidDataChars = regexp.MustCompile("[^a-zA-Z0-9-._]+") | ||||
| var invalidStartEndChars = regexp.MustCompile("(^[^a-zA-Z0-9-._]+|[^a-zA-Z0-9-._]+$)") | ||||
|  | ||||
| func createValidSecretDataName(value string) string { | ||||
| 	result := invalidStartEndChars.ReplaceAllString(value, "") | ||||
| 	result = invalidDataChars.ReplaceAllString(result, "-") | ||||
|  | ||||
| 	if len(result) > kubeValidate.DNS1123SubdomainMaxLength { | ||||
| 		result = result[0:kubeValidate.DNS1123SubdomainMaxLength] | ||||
| 	} | ||||
|  | ||||
| 	return result | ||||
| } | ||||
|   | ||||
| @@ -6,11 +6,10 @@ import ( | ||||
| 	"strings" | ||||
| 	"testing" | ||||
|  | ||||
| 	kubeValidate "k8s.io/apimachinery/pkg/util/validation" | ||||
|  | ||||
| 	"github.com/1Password/connect-sdk-go/onepassword" | ||||
| 	corev1 "k8s.io/api/core/v1" | ||||
| 	"k8s.io/apimachinery/pkg/types" | ||||
| 	kubeValidate "k8s.io/apimachinery/pkg/util/validation" | ||||
| 	"k8s.io/client-go/kubernetes" | ||||
| 	"sigs.k8s.io/controller-runtime/pkg/client/fake" | ||||
| ) | ||||
| @@ -32,7 +31,11 @@ func TestCreateKubernetesSecretFromOnePasswordItem(t *testing.T) { | ||||
| 	item.ID = "h46bb3jddvay7nxopfhvlwg35q" | ||||
|  | ||||
| 	kubeClient := fake.NewFakeClient() | ||||
| 	err := CreateKubernetesSecretFromItem(kubeClient, secretName, namespace, &item, restartDeploymentAnnotation) | ||||
| 	secretLabels := map[string]string{} | ||||
| 	secretAnnotations := map[string]string{ | ||||
| 		"testAnnotation": "exists", | ||||
| 	} | ||||
| 	err := CreateKubernetesSecretFromItem(kubeClient, secretName, namespace, &item, restartDeploymentAnnotation, secretLabels, secretAnnotations) | ||||
| 	if err != nil { | ||||
| 		t.Errorf("Unexpected error: %v", err) | ||||
| 	} | ||||
| @@ -43,7 +46,11 @@ func TestCreateKubernetesSecretFromOnePasswordItem(t *testing.T) { | ||||
| 		t.Errorf("Secret was not created: %v", err) | ||||
| 	} | ||||
| 	compareFields(item.Fields, createdSecret.Data, t) | ||||
| 	compareAnnotationsToItem(item.Vault.ID, item.ID, createdSecret.Annotations, item, t) | ||||
| 	compareAnnotationsToItem(createdSecret.Annotations, item, t) | ||||
|  | ||||
| 	if createdSecret.Annotations["testAnnotation"] != "exists" { | ||||
| 		t.Errorf("Expected testAnnotation to be merged with existing annotations, but wasn't.") | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestUpdateKubernetesSecretFromOnePasswordItem(t *testing.T) { | ||||
| @@ -57,7 +64,9 @@ func TestUpdateKubernetesSecretFromOnePasswordItem(t *testing.T) { | ||||
| 	item.ID = "h46bb3jddvay7nxopfhvlwg35q" | ||||
|  | ||||
| 	kubeClient := fake.NewFakeClient() | ||||
| 	err := CreateKubernetesSecretFromItem(kubeClient, secretName, namespace, &item, restartDeploymentAnnotation) | ||||
| 	secretLabels := map[string]string{} | ||||
| 	secretAnnotations := map[string]string{} | ||||
| 	err := CreateKubernetesSecretFromItem(kubeClient, secretName, namespace, &item, restartDeploymentAnnotation, secretLabels, secretAnnotations) | ||||
| 	if err != nil { | ||||
| 		t.Errorf("Unexpected error: %v", err) | ||||
| 	} | ||||
| @@ -68,7 +77,7 @@ func TestUpdateKubernetesSecretFromOnePasswordItem(t *testing.T) { | ||||
| 	newItem.Version = 456 | ||||
| 	newItem.Vault.ID = "hfnjvi6aymbsnfc2xeeoheizda" | ||||
| 	newItem.ID = "h46bb3jddvay7nxopfhvlwg35q" | ||||
| 	err = CreateKubernetesSecretFromItem(kubeClient, secretName, namespace, &newItem, restartDeploymentAnnotation) | ||||
| 	err = CreateKubernetesSecretFromItem(kubeClient, secretName, namespace, &newItem, restartDeploymentAnnotation, secretLabels, secretAnnotations) | ||||
| 	if err != nil { | ||||
| 		t.Errorf("Unexpected error: %v", err) | ||||
| 	} | ||||
| @@ -79,7 +88,7 @@ func TestUpdateKubernetesSecretFromOnePasswordItem(t *testing.T) { | ||||
| 		t.Errorf("Secret was not found: %v", err) | ||||
| 	} | ||||
| 	compareFields(newItem.Fields, updatedSecret.Data, t) | ||||
| 	compareAnnotationsToItem(newItem.Vault.ID, newItem.ID, updatedSecret.Annotations, newItem, t) | ||||
| 	compareAnnotationsToItem(updatedSecret.Annotations, newItem, t) | ||||
| } | ||||
| func TestBuildKubernetesSecretData(t *testing.T) { | ||||
| 	fields := generateFields(5) | ||||
| @@ -101,8 +110,9 @@ func TestBuildKubernetesSecretFromOnePasswordItem(t *testing.T) { | ||||
| 	} | ||||
| 	item := onepassword.Item{} | ||||
| 	item.Fields = generateFields(5) | ||||
| 	labels := map[string]string{} | ||||
|  | ||||
| 	kubeSecret := BuildKubernetesSecretFromOnePasswordItem(name, namespace, annotations, item) | ||||
| 	kubeSecret := BuildKubernetesSecretFromOnePasswordItem(name, namespace, annotations, labels, item) | ||||
| 	if kubeSecret.Name != strings.ToLower(name) { | ||||
| 		t.Errorf("Expected name value: %v but got: %v", name, kubeSecret.Name) | ||||
| 	} | ||||
| @@ -122,6 +132,7 @@ func TestBuildKubernetesSecretFixesInvalidLabels(t *testing.T) { | ||||
| 	annotations := map[string]string{ | ||||
| 		"annotationKey": "annotationValue", | ||||
| 	} | ||||
| 	labels := map[string]string{} | ||||
| 	item := onepassword.Item{} | ||||
|  | ||||
| 	item.Fields = []*onepassword.ItemField{ | ||||
| @@ -135,7 +146,7 @@ func TestBuildKubernetesSecretFixesInvalidLabels(t *testing.T) { | ||||
| 		}, | ||||
| 	} | ||||
|  | ||||
| 	kubeSecret := BuildKubernetesSecretFromOnePasswordItem(name, namespace, annotations, item) | ||||
| 	kubeSecret := BuildKubernetesSecretFromOnePasswordItem(name, namespace, annotations, labels,  item) | ||||
|  | ||||
| 	// Assert Secret's meta.name was fixed | ||||
| 	if kubeSecret.Name != expectedName { | ||||
| @@ -153,7 +164,11 @@ func TestBuildKubernetesSecretFixesInvalidLabels(t *testing.T) { | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func compareAnnotationsToItem(actualVaultId, actualItemId string, annotations map[string]string, item onepassword.Item, t *testing.T) { | ||||
| func compareAnnotationsToItem(annotations map[string]string, item onepassword.Item, t *testing.T) { | ||||
| 	actualVaultId, actualItemId, err := ParseVaultIdAndItemIdFromPath(annotations[ItemPathAnnotation]) | ||||
| 	if err != nil { | ||||
| 		t.Errorf("Was unable to parse Item Path") | ||||
| 	} | ||||
| 	if actualVaultId != item.Vault.ID { | ||||
| 		t.Errorf("Expected annotation vault id to be %v but was %v", item.Vault.ID, actualVaultId) | ||||
| 	} | ||||
| @@ -193,8 +208,16 @@ func generateFields(numToGenerate int) []*onepassword.ItemField { | ||||
| 	return fields | ||||
| } | ||||
|  | ||||
| func ParseVaultIdAndItemIdFromPath(path string) (string, string, error) { | ||||
| 	splitPath := strings.Split(path, "/") | ||||
| 	if len(splitPath) == 4 && splitPath[0] == "vaults" && splitPath[2] == "items" { | ||||
| 		return splitPath[1], splitPath[3], nil | ||||
| 	} | ||||
| 	return "", "", fmt.Errorf("%q is not an acceptable path for One Password item. Must be of the format: `vaults/{vault_id}/items/{item_id}`", path) | ||||
| } | ||||
|  | ||||
| func validLabel(v string) bool { | ||||
| 	if err := kubeValidate.IsDNS1123Subdomain(v); len(err) > 0 { | ||||
| 	if err := kubeValidate.IsConfigMapKey(v); len(err) > 0 { | ||||
| 		return false | ||||
| 	} | ||||
| 	return true | ||||
|   | ||||
| @@ -9,7 +9,7 @@ import ( | ||||
|  | ||||
| const ( | ||||
| 	OnepasswordPrefix            = "operator.1password.io" | ||||
| 	ItemReferenceAnnotation      = OnepasswordPrefix + "/item-reference" | ||||
| 	ItemPathAnnotation           = OnepasswordPrefix + "/item-path" | ||||
| 	NameAnnotation               = OnepasswordPrefix + "/item-name" | ||||
| 	VersionAnnotation            = OnepasswordPrefix + "/item-version" | ||||
| 	RestartAnnotation            = OnepasswordPrefix + "/last-restarted" | ||||
|   | ||||
| @@ -22,7 +22,7 @@ func TestFilterAnnotations(t *testing.T) { | ||||
| 	if len(filteredAnnotations) != 2 { | ||||
| 		t.Errorf("Unexpected number of filtered annotations returned. Expected 2, got %v", len(filteredAnnotations)) | ||||
| 	} | ||||
| 	_, found := filteredAnnotations[ItemReferenceAnnotation] | ||||
| 	_, found := filteredAnnotations[ItemPathAnnotation] | ||||
| 	if !found { | ||||
| 		t.Errorf("One Password Annotation was filtered when it should not have been") | ||||
| 	} | ||||
| @@ -87,7 +87,7 @@ func TestGetNoAnnotationsForDeployment(t *testing.T) { | ||||
|  | ||||
| func getValidAnnotations() map[string]string { | ||||
| 	return map[string]string{ | ||||
| 		ItemReferenceAnnotation: "op://b3e4c7fc-8bf7-4c22-b8bb-147539f10e4f/b3e4c7fc-8bf7-4c22-b8bb-147539f10e4f", | ||||
| 		NameAnnotation:          "secretName", | ||||
| 		ItemPathAnnotation: "vaults/b3e4c7fc-8bf7-4c22-b8bb-147539f10e4f/items/b3e4c7fc-8bf7-4c22-b8bb-147539f10e4f", | ||||
| 		NameAnnotation:     "secretName", | ||||
| 	} | ||||
| } | ||||
|   | ||||
| @@ -11,16 +11,11 @@ import ( | ||||
|  | ||||
| var logger = logf.Log.WithName("retrieve_item") | ||||
|  | ||||
| const ( | ||||
| 	secretReferencePrefix = "op://" | ||||
| ) | ||||
|  | ||||
| func GetOnePasswordItemByReference(opConnectClient connect.Client, reference string) (*onepassword.Item, error) { | ||||
| 	vaultValue, itemValue, err := ParseReference(reference) | ||||
| func GetOnePasswordItemByPath(opConnectClient connect.Client, path string) (*onepassword.Item, error) { | ||||
| 	vaultValue, itemValue, err := ParseVaultAndItemFromPath(path) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
|  | ||||
| 	vaultId, err := getVaultId(opConnectClient, vaultValue) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| @@ -38,28 +33,12 @@ func GetOnePasswordItemByReference(opConnectClient connect.Client, reference str | ||||
| 	return item, nil | ||||
| } | ||||
|  | ||||
| func ParseReference(reference string) (string, string, error) { | ||||
| 	if !strings.HasPrefix(reference, secretReferencePrefix) { | ||||
| 		return "", "", fmt.Errorf("secret reference should start with `op://`") | ||||
| 	} | ||||
| 	path := strings.TrimPrefix(reference, secretReferencePrefix) | ||||
|  | ||||
| func ParseVaultAndItemFromPath(path string) (string, string, error) { | ||||
| 	splitPath := strings.Split(path, "/") | ||||
| 	if len(splitPath) != 2 { | ||||
| 		return "", "", fmt.Errorf("Invalid secret reference : %s. Secret references should match op://<vault>/<item>", reference) | ||||
| 	if len(splitPath) == 4 && splitPath[0] == "vaults" && splitPath[2] == "items" { | ||||
| 		return splitPath[1], splitPath[3], nil | ||||
| 	} | ||||
|  | ||||
| 	vault := splitPath[0] | ||||
| 	if vault == "" { | ||||
| 		return "", "", fmt.Errorf("Invalid secret reference : %s. Vault can't be empty.", reference) | ||||
| 	} | ||||
|  | ||||
| 	item := splitPath[1] | ||||
| 	if item == "" { | ||||
| 		return "", "", fmt.Errorf("Invalid secret reference : %s. Item can't be empty.", reference) | ||||
| 	} | ||||
|  | ||||
| 	return vault, item, nil | ||||
| 	return "", "", fmt.Errorf("%q is not an acceptable path for One Password item. Must be of the format: `vaults/{vault_id}/items/{item_id}`", path) | ||||
| } | ||||
|  | ||||
| func getVaultId(client connect.Client, vaultIdentifier string) (string, error) { | ||||
|   | ||||
| @@ -110,13 +110,13 @@ func (h *SecretUpdateHandler) updateKubernetesSecrets() (map[string]map[string]* | ||||
| 	for i := 0; i < len(secrets.Items); i++ { | ||||
| 		secret := secrets.Items[i] | ||||
|  | ||||
| 		itemReference := secret.Annotations[ItemReferenceAnnotation] | ||||
| 		itemPath := secret.Annotations[ItemPathAnnotation] | ||||
| 		currentVersion := secret.Annotations[VersionAnnotation] | ||||
| 		if len(itemReference) == 0 || len(currentVersion) == 0 { | ||||
| 		if len(itemPath) == 0 || len(currentVersion) == 0 { | ||||
| 			continue | ||||
| 		} | ||||
|  | ||||
| 		item, err := GetOnePasswordItemByReference(h.opConnectClient, secret.Annotations[ItemReferenceAnnotation]) | ||||
| 		item, err := GetOnePasswordItemByPath(h.opConnectClient, secret.Annotations[ItemPathAnnotation]) | ||||
| 		if err != nil { | ||||
| 			return nil, fmt.Errorf("Failed to retrieve item: %v", err) | ||||
| 		} | ||||
| @@ -131,7 +131,7 @@ func (h *SecretUpdateHandler) updateKubernetesSecrets() (map[string]map[string]* | ||||
| 			} | ||||
| 			log.Info(fmt.Sprintf("Updating kubernetes secret '%v'", secret.GetName())) | ||||
| 			secret.Annotations[VersionAnnotation] = itemVersion | ||||
| 			updatedSecret := kubeSecrets.BuildKubernetesSecretFromOnePasswordItem(secret.Name, secret.Namespace, secret.Annotations, *item) | ||||
| 			updatedSecret := kubeSecrets.BuildKubernetesSecretFromOnePasswordItem(secret.Name, secret.Namespace, secret.Annotations, secret.Labels, *item) | ||||
| 			h.client.Update(context.Background(), updatedSecret) | ||||
| 			if updatedSecrets[secret.Namespace] == nil { | ||||
| 				updatedSecrets[secret.Namespace] = make(map[string]*corev1.Secret) | ||||
|   | ||||
| @@ -51,7 +51,7 @@ var ( | ||||
| 		"password": []byte(password), | ||||
| 		"username": []byte(username), | ||||
| 	} | ||||
| 	itemReference = fmt.Sprintf("op://%v/%v", vaultId, itemId) | ||||
| 	itemPath = fmt.Sprintf("vaults/%v/items/%v", vaultId, itemId) | ||||
| ) | ||||
|  | ||||
| var defaultNamespace = &corev1.Namespace{ | ||||
| @@ -73,8 +73,8 @@ var tests = []testUpdateSecretTask{ | ||||
| 				Name:      name, | ||||
| 				Namespace: namespace, | ||||
| 				Annotations: map[string]string{ | ||||
| 					NameAnnotation:          "unlrelated secret", | ||||
| 					ItemReferenceAnnotation: itemReference, | ||||
| 					NameAnnotation:     "unlrelated secret", | ||||
| 					ItemPathAnnotation: itemPath, | ||||
| 				}, | ||||
| 			}, | ||||
| 		}, | ||||
| @@ -83,8 +83,8 @@ var tests = []testUpdateSecretTask{ | ||||
| 				Name:      name, | ||||
| 				Namespace: namespace, | ||||
| 				Annotations: map[string]string{ | ||||
| 					VersionAnnotation:       "old version", | ||||
| 					ItemReferenceAnnotation: itemReference, | ||||
| 					VersionAnnotation:  "old version", | ||||
| 					ItemPathAnnotation: itemPath, | ||||
| 				}, | ||||
| 			}, | ||||
| 			Data: expectedSecretData, | ||||
| @@ -95,8 +95,8 @@ var tests = []testUpdateSecretTask{ | ||||
| 				Name:      name, | ||||
| 				Namespace: namespace, | ||||
| 				Annotations: map[string]string{ | ||||
| 					VersionAnnotation:       fmt.Sprint(itemVersion), | ||||
| 					ItemReferenceAnnotation: itemReference, | ||||
| 					VersionAnnotation:  fmt.Sprint(itemVersion), | ||||
| 					ItemPathAnnotation: itemPath, | ||||
| 				}, | ||||
| 			}, | ||||
| 			Data: expectedSecretData, | ||||
| @@ -149,8 +149,8 @@ var tests = []testUpdateSecretTask{ | ||||
| 				Name:      name, | ||||
| 				Namespace: namespace, | ||||
| 				Annotations: map[string]string{ | ||||
| 					VersionAnnotation:       "old version", | ||||
| 					ItemReferenceAnnotation: itemReference, | ||||
| 					VersionAnnotation:  "old version", | ||||
| 					ItemPathAnnotation: itemPath, | ||||
| 				}, | ||||
| 			}, | ||||
| 			Data: expectedSecretData, | ||||
| @@ -161,8 +161,8 @@ var tests = []testUpdateSecretTask{ | ||||
| 				Name:      name, | ||||
| 				Namespace: namespace, | ||||
| 				Annotations: map[string]string{ | ||||
| 					VersionAnnotation:       fmt.Sprint(itemVersion), | ||||
| 					ItemReferenceAnnotation: itemReference, | ||||
| 					VersionAnnotation:  fmt.Sprint(itemVersion), | ||||
| 					ItemPathAnnotation: itemPath, | ||||
| 				}, | ||||
| 			}, | ||||
| 			Data: expectedSecretData, | ||||
| @@ -186,8 +186,8 @@ var tests = []testUpdateSecretTask{ | ||||
| 				Name:      name, | ||||
| 				Namespace: namespace, | ||||
| 				Annotations: map[string]string{ | ||||
| 					ItemReferenceAnnotation: itemReference, | ||||
| 					NameAnnotation:          name, | ||||
| 					ItemPathAnnotation: itemPath, | ||||
| 					NameAnnotation:     name, | ||||
| 				}, | ||||
| 			}, | ||||
| 		}, | ||||
| @@ -196,8 +196,8 @@ var tests = []testUpdateSecretTask{ | ||||
| 				Name:      name, | ||||
| 				Namespace: namespace, | ||||
| 				Annotations: map[string]string{ | ||||
| 					VersionAnnotation:       "old version", | ||||
| 					ItemReferenceAnnotation: itemReference, | ||||
| 					VersionAnnotation:  "old version", | ||||
| 					ItemPathAnnotation: itemPath, | ||||
| 				}, | ||||
| 			}, | ||||
| 			Data: expectedSecretData, | ||||
| @@ -208,8 +208,8 @@ var tests = []testUpdateSecretTask{ | ||||
| 				Name:      name, | ||||
| 				Namespace: namespace, | ||||
| 				Annotations: map[string]string{ | ||||
| 					VersionAnnotation:       fmt.Sprint(itemVersion), | ||||
| 					ItemReferenceAnnotation: itemReference, | ||||
| 					VersionAnnotation:  fmt.Sprint(itemVersion), | ||||
| 					ItemPathAnnotation: itemPath, | ||||
| 				}, | ||||
| 			}, | ||||
| 			Data: expectedSecretData, | ||||
| @@ -255,8 +255,8 @@ var tests = []testUpdateSecretTask{ | ||||
| 				Name:      name, | ||||
| 				Namespace: namespace, | ||||
| 				Annotations: map[string]string{ | ||||
| 					VersionAnnotation:       "old version", | ||||
| 					ItemReferenceAnnotation: itemReference, | ||||
| 					VersionAnnotation:  "old version", | ||||
| 					ItemPathAnnotation: itemPath, | ||||
| 				}, | ||||
| 			}, | ||||
| 			Data: expectedSecretData, | ||||
| @@ -267,8 +267,8 @@ var tests = []testUpdateSecretTask{ | ||||
| 				Name:      name, | ||||
| 				Namespace: namespace, | ||||
| 				Annotations: map[string]string{ | ||||
| 					VersionAnnotation:       fmt.Sprint(itemVersion), | ||||
| 					ItemReferenceAnnotation: itemReference, | ||||
| 					VersionAnnotation:  fmt.Sprint(itemVersion), | ||||
| 					ItemPathAnnotation: itemPath, | ||||
| 				}, | ||||
| 			}, | ||||
| 			Data: expectedSecretData, | ||||
| @@ -292,8 +292,8 @@ var tests = []testUpdateSecretTask{ | ||||
| 				Name:      name, | ||||
| 				Namespace: namespace, | ||||
| 				Annotations: map[string]string{ | ||||
| 					ItemReferenceAnnotation: itemReference, | ||||
| 					NameAnnotation:          name, | ||||
| 					ItemPathAnnotation: itemPath, | ||||
| 					NameAnnotation:     name, | ||||
| 				}, | ||||
| 			}, | ||||
| 		}, | ||||
| @@ -302,8 +302,8 @@ var tests = []testUpdateSecretTask{ | ||||
| 				Name:      name, | ||||
| 				Namespace: namespace, | ||||
| 				Annotations: map[string]string{ | ||||
| 					VersionAnnotation:       fmt.Sprint(itemVersion), | ||||
| 					ItemReferenceAnnotation: itemReference, | ||||
| 					VersionAnnotation:  fmt.Sprint(itemVersion), | ||||
| 					ItemPathAnnotation: itemPath, | ||||
| 				}, | ||||
| 			}, | ||||
| 			Data: expectedSecretData, | ||||
| @@ -314,8 +314,8 @@ var tests = []testUpdateSecretTask{ | ||||
| 				Name:      name, | ||||
| 				Namespace: namespace, | ||||
| 				Annotations: map[string]string{ | ||||
| 					VersionAnnotation:       fmt.Sprint(itemVersion), | ||||
| 					ItemReferenceAnnotation: itemReference, | ||||
| 					VersionAnnotation:  fmt.Sprint(itemVersion), | ||||
| 					ItemPathAnnotation: itemPath, | ||||
| 				}, | ||||
| 			}, | ||||
| 			Data: expectedSecretData, | ||||
| @@ -369,8 +369,8 @@ var tests = []testUpdateSecretTask{ | ||||
| 				Name:      name, | ||||
| 				Namespace: namespace, | ||||
| 				Annotations: map[string]string{ | ||||
| 					VersionAnnotation:       "old version", | ||||
| 					ItemReferenceAnnotation: itemReference, | ||||
| 					VersionAnnotation:  "old version", | ||||
| 					ItemPathAnnotation: itemPath, | ||||
| 				}, | ||||
| 			}, | ||||
| 			Data: expectedSecretData, | ||||
| @@ -381,8 +381,8 @@ var tests = []testUpdateSecretTask{ | ||||
| 				Name:      name, | ||||
| 				Namespace: namespace, | ||||
| 				Annotations: map[string]string{ | ||||
| 					VersionAnnotation:       fmt.Sprint(itemVersion), | ||||
| 					ItemReferenceAnnotation: itemReference, | ||||
| 					VersionAnnotation:  fmt.Sprint(itemVersion), | ||||
| 					ItemPathAnnotation: itemPath, | ||||
| 				}, | ||||
| 			}, | ||||
| 			Data: expectedSecretData, | ||||
| @@ -439,7 +439,7 @@ var tests = []testUpdateSecretTask{ | ||||
| 				Namespace: namespace, | ||||
| 				Annotations: map[string]string{ | ||||
| 					VersionAnnotation:            "old version", | ||||
| 					ItemReferenceAnnotation:      itemReference, | ||||
| 					ItemPathAnnotation:           itemPath, | ||||
| 					RestartDeploymentsAnnotation: "true", | ||||
| 				}, | ||||
| 			}, | ||||
| @@ -452,7 +452,7 @@ var tests = []testUpdateSecretTask{ | ||||
| 				Namespace: namespace, | ||||
| 				Annotations: map[string]string{ | ||||
| 					VersionAnnotation:            fmt.Sprint(itemVersion), | ||||
| 					ItemReferenceAnnotation:      itemReference, | ||||
| 					ItemPathAnnotation:           itemPath, | ||||
| 					RestartDeploymentsAnnotation: "true", | ||||
| 				}, | ||||
| 			}, | ||||
| @@ -510,7 +510,7 @@ var tests = []testUpdateSecretTask{ | ||||
| 				Namespace: namespace, | ||||
| 				Annotations: map[string]string{ | ||||
| 					VersionAnnotation:            "old version", | ||||
| 					ItemReferenceAnnotation:      itemReference, | ||||
| 					ItemPathAnnotation:           itemPath, | ||||
| 					RestartDeploymentsAnnotation: "false", | ||||
| 				}, | ||||
| 			}, | ||||
| @@ -523,7 +523,7 @@ var tests = []testUpdateSecretTask{ | ||||
| 				Namespace: namespace, | ||||
| 				Annotations: map[string]string{ | ||||
| 					VersionAnnotation:            fmt.Sprint(itemVersion), | ||||
| 					ItemReferenceAnnotation:      itemReference, | ||||
| 					ItemPathAnnotation:           itemPath, | ||||
| 					RestartDeploymentsAnnotation: "false", | ||||
| 				}, | ||||
| 			}, | ||||
| @@ -580,8 +580,8 @@ var tests = []testUpdateSecretTask{ | ||||
| 				Name:      name, | ||||
| 				Namespace: namespace, | ||||
| 				Annotations: map[string]string{ | ||||
| 					VersionAnnotation:       "old version", | ||||
| 					ItemReferenceAnnotation: itemReference, | ||||
| 					VersionAnnotation:  "old version", | ||||
| 					ItemPathAnnotation: itemPath, | ||||
| 				}, | ||||
| 			}, | ||||
| 			Data: expectedSecretData, | ||||
| @@ -592,8 +592,8 @@ var tests = []testUpdateSecretTask{ | ||||
| 				Name:      name, | ||||
| 				Namespace: namespace, | ||||
| 				Annotations: map[string]string{ | ||||
| 					VersionAnnotation:       fmt.Sprint(itemVersion), | ||||
| 					ItemReferenceAnnotation: itemReference, | ||||
| 					VersionAnnotation:  fmt.Sprint(itemVersion), | ||||
| 					ItemPathAnnotation: itemPath, | ||||
| 				}, | ||||
| 			}, | ||||
| 			Data: expectedSecretData, | ||||
| @@ -657,8 +657,8 @@ var tests = []testUpdateSecretTask{ | ||||
| 				Name:      name, | ||||
| 				Namespace: namespace, | ||||
| 				Annotations: map[string]string{ | ||||
| 					VersionAnnotation:       "old version", | ||||
| 					ItemReferenceAnnotation: itemReference, | ||||
| 					VersionAnnotation:  "old version", | ||||
| 					ItemPathAnnotation: itemPath, | ||||
| 				}, | ||||
| 			}, | ||||
| 			Data: expectedSecretData, | ||||
| @@ -669,8 +669,8 @@ var tests = []testUpdateSecretTask{ | ||||
| 				Name:      name, | ||||
| 				Namespace: namespace, | ||||
| 				Annotations: map[string]string{ | ||||
| 					VersionAnnotation:       fmt.Sprint(itemVersion), | ||||
| 					ItemReferenceAnnotation: itemReference, | ||||
| 					VersionAnnotation:  fmt.Sprint(itemVersion), | ||||
| 					ItemPathAnnotation: itemPath, | ||||
| 				}, | ||||
| 			}, | ||||
| 			Data: expectedSecretData, | ||||
| @@ -730,8 +730,8 @@ var tests = []testUpdateSecretTask{ | ||||
| 				Name:      name, | ||||
| 				Namespace: namespace, | ||||
| 				Annotations: map[string]string{ | ||||
| 					VersionAnnotation:       "old version", | ||||
| 					ItemReferenceAnnotation: itemReference, | ||||
| 					VersionAnnotation:  "old version", | ||||
| 					ItemPathAnnotation: itemPath, | ||||
| 				}, | ||||
| 			}, | ||||
| 			Data: expectedSecretData, | ||||
| @@ -742,8 +742,8 @@ var tests = []testUpdateSecretTask{ | ||||
| 				Name:      name, | ||||
| 				Namespace: namespace, | ||||
| 				Annotations: map[string]string{ | ||||
| 					VersionAnnotation:       fmt.Sprint(itemVersion), | ||||
| 					ItemReferenceAnnotation: itemReference, | ||||
| 					VersionAnnotation:  fmt.Sprint(itemVersion), | ||||
| 					ItemPathAnnotation: itemPath, | ||||
| 				}, | ||||
| 			}, | ||||
| 			Data: expectedSecretData, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user