Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compute digest of configmap and secret from its data #5115

Merged
merged 6 commits into from
Feb 12, 2024

Conversation

lfabriko
Copy link
Contributor

Proposal of fix to #5114 - use Name, Namespace and Data/StringData to compute digest of Configmap and Secret.

Copy link
Contributor

@squakez squakez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tested against the issued sample reported? I am not entirely sure the reason of the behavior is how we calculate digest.

@lfabriko
Copy link
Contributor Author

I think it tries to compute digest of configmap from memory address: (digest.go)


	// Configmap and secret content
	for _, cm := range configmaps {
		//DEBUG
		if cm != nil {
			log.Infof(fmt.Sprintf("LFAB3 configmap cm.String: %s", cm.String()))
		} else {
			log.Infof(fmt.Sprintf("LFAB3 cm is nil"))
		}
		//END OF DEBUG
		if _, err := hash.Write([]byte(cm.String())); err != nil {
			return "", err
		}
	}

I observed (in build_kit.go) before cm.yaml configmap is loaded, secrets, configmaps := getIntegrationSecretsAndConfigmaps(ctx, action.client, integration) returns [nil] as configmaps (it doesn't change digest).
When the cm is loaded, digest.ComputeForIntegration computes hash from whole configmap object via cm.String(), it seems to me it takes also the memory address, which keeps changing, so next step in build_kit.go if hash != integration.Status.Digest { is always different.

After adding debugging notes:

{"level":"info","ts":"2024-01-29T09:12:00Z","logger":"camel-k","msg":"LFAB3 cm is nil"}
...
{"level":"info","ts":"2024-01-29T09:13:00Z","logger":"camel-k","msg":"LFAB3 configmap cm.String: &ConfigMap{ObjectMeta:{myconfigmap  lfabriko  6c693d68-2f0c-46b8-a5b3-a75cb5219211 60808454 0 2024-01-29 09:12:42 +0000 UTC <nil> <nil> map[] map[kubectl.kubernetes.io/last-applied-configuration:{\"apiVersion\":\"v1\",\"data\":{\"bar\":\"2\",\"foo\":\"1\"},\"kind\":\"ConfigMap\",\"metadata\":{\"annotations\":{},\"name\":\"myconfigmap\",\"namespace\":\"lfabriko\",\"ownerReferences\":[{\"apiVersion\":\"camel.apache.org/v1\",\"blockOwnerDeletion\":true,\"controller\":true,\"kind\":\"Integration\",\"name\":\"myintegration\",\"uid\":\"48e97e9e-6eb8-4cb2-9f9b-736521f16ee8\"}]}}\n] [{camel.apache.org/v1 Integration myintegration 48e97e9e-6eb8-4cb2-9f9b-736521f16ee8 0xc0012acd2d 0xc0012acd2e}] [] [{kubectl-client-side-apply Update v1 2024-01-29 09:12:42 +0000 UTC FieldsV1 {\"f:data\":{\".\":{},\"f:bar\":{},\"f:foo\":{}},\"f:metadata\":{\"f:annotations\":{\".\":{},\"f:kubectl.kubernetes.io/last-applied-configuration\":{}},\"f:ownerReferences\":{\".\":{},\"k:{\\\"uid\\\":\\\"48e97e9e-6eb8-4cb2-9f9b-736521f16ee8\\\"}\":{}}}} }]},Data:map[string]string{bar: 2,foo: 1,},BinaryData:map[string][]byte{},Immutable:nil,}"}
{"level":"info","ts":"2024-01-29T09:13:00Z","logger":"camel-k","msg":"LFAB3 digest vEQhvrHzidhCwTIGgGASlVTKlaW9-pFHuV08xkGVQxsQ"}

{"level":"info","ts":"2024-01-29T09:13:00Z","logger":"camel-k","msg":"LFAB3 configmap cm.String: &ConfigMap{ObjectMeta:{myconfigmap  lfabriko  6c693d68-2f0c-46b8-a5b3-a75cb5219211 60808454 0 2024-01-29 09:12:42 +0000 UTC <nil> <nil> map[] map[kubectl.kubernetes.io/last-applied-configuration:{\"apiVersion\":\"v1\",\"data\":{\"bar\":\"2\",\"foo\":\"1\"},\"kind\":\"ConfigMap\",\"metadata\":{\"annotations\":{},\"name\":\"myconfigmap\",\"namespace\":\"lfabriko\",\"ownerReferences\":[{\"apiVersion\":\"camel.apache.org/v1\",\"blockOwnerDeletion\":true,\"controller\":true,\"kind\":\"Integration\",\"name\":\"myintegration\",\"uid\":\"48e97e9e-6eb8-4cb2-9f9b-736521f16ee8\"}]}}\n] [{camel.apache.org/v1 Integration myintegration 48e97e9e-6eb8-4cb2-9f9b-736521f16ee8 0xc0012ace07 0xc0012ace08}] [] [{kubectl-client-side-apply Update v1 2024-01-29 09:12:42 +0000 UTC FieldsV1 {\"f:data\":{\".\":{},\"f:bar\":{},\"f:foo\":{}},\"f:metadata\":{\"f:annotations\":{\".\":{},\"f:kubectl.kubernetes.io/last-applied-configuration\":{}},\"f:ownerReferences\":{\".\":{},\"k:{\\\"uid\\\":\\\"48e97e9e-6eb8-4cb2-9f9b-736521f16ee8\\\"}\":{}}}} }]},Data:map[string]string{bar: 2,foo: 1,},BinaryData:map[string][]byte{},Immutable:nil,}"}
{"level":"info","ts":"2024-01-29T09:13:00Z","logger":"camel-k","msg":"LFAB3 digest vra0Ihy7JAv6YXdpCCbcno8lWWM7MP6ud38zXLdW-0J0"}

{"level":"info","ts":"2024-01-29T09:13:00Z","logger":"camel-k","msg":"LFAB3 configmap cm.String: &ConfigMap{ObjectMeta:{myconfigmap  lfabriko  6c693d68-2f0c-46b8-a5b3-a75cb5219211 60808454 0 2024-01-29 09:12:42 +0000 UTC <nil> <nil> map[] map[kubectl.kubernetes.io/last-applied-configuration:{\"apiVersion\":\"v1\",\"data\":{\"bar\":\"2\",\"foo\":\"1\"},\"kind\":\"ConfigMap\",\"metadata\":{\"annotations\":{},\"name\":\"myconfigmap\",\"namespace\":\"lfabriko\",\"ownerReferences\":[{\"apiVersion\":\"camel.apache.org/v1\",\"blockOwnerDeletion\":true,\"controller\":true,\"kind\":\"Integration\",\"name\":\"myintegration\",\"uid\":\"48e97e9e-6eb8-4cb2-9f9b-736521f16ee8\"}]}}\n] [{camel.apache.org/v1 Integration myintegration 48e97e9e-6eb8-4cb2-9f9b-736521f16ee8 0xc001ca42e0 0xc001ca42e1}] [] [{kubectl-client-side-apply Update v1 2024-01-29 09:12:42 +0000 UTC FieldsV1 {\"f:data\":{\".\":{},\"f:bar\":{},\"f:foo\":{}},\"f:metadata\":{\"f:annotations\":{\".\":{},\"f:kubectl.kubernetes.io/last-applied-configuration\":{}},\"f:ownerReferences\":{\".\":{},\"k:{\\\"uid\\\":\\\"48e97e9e-6eb8-4cb2-9f9b-736521f16ee8\\\"}\":{}}}} }]},Data:map[string]string{bar: 2,foo: 1,},BinaryData:map[string][]byte{},Immutable:nil,}"}
{"level":"info","ts":"2024-01-29T09:13:00Z","logger":"camel-k","msg":"LFAB3 digest vzFRVYBlBtbp_8dPiB9Zx5A9gLj33R8YGOZV9xHTbCkI"}


I tried it against both 5115 and config_reload_test.go.

@lfabriko
Copy link
Contributor Author

lfabriko commented Jan 29, 2024

I observe if configmap is created without the ownerReference part (ie. order of creation is 1. configmap, 2. integration) there isn't the memory reference and the case 5115 doesn't appear:

{"level":"info","ts":"2024-01-29T09:28:41Z","logger":"camel-k","msg":"LFAB3 configmap cm.String: &ConfigMap{ObjectMeta:{myconfigmap  lfabriko  fe6aab0c-d21a-4628-b5f6-a2d945c4b9a6 60826770 0 2024-01-29 09:24:23 +0000 UTC <nil> <nil> map[] map[kubectl.kubernetes.io/last-applied-configuration:{\"apiVersion\":\"v1\",\"data\":{\"bar\":\"2\",\"foo\":\"1\"},\"kind\":\"ConfigMap\",\"metadata\":{\"annotations\":{},\"name\":\"myconfigmap\",\"namespace\":\"lfabriko\"}}\n] [] [] [{kubectl-client-side-apply Update v1 2024-01-29 09:24:23 +0000 UTC FieldsV1 {\"f:data\":{\".\":{},\"f:bar\":{},\"f:foo\":{}},\"f:metadata\":{\"f:annotations\":{\".\":{},\"f:kubectl.kubernetes.io/last-applied-configuration\":{}}}} }]},Data:map[string]string{bar: 2,foo: 1,},BinaryData:map[string][]byte{},Immutable:nil,}"}
{"level":"info","ts":"2024-01-29T09:28:41Z","logger":"camel-k","msg":"LFAB3 digest v7q7PJwFnLoEd4_wTiIOwkIRVaZHha7n77tCOXz2KH50"}

{"level":"info","ts":"2024-01-29T09:28:41Z","logger":"camel-k","msg":"LFAB3 configmap cm.String: &ConfigMap{ObjectMeta:{myconfigmap  lfabriko  fe6aab0c-d21a-4628-b5f6-a2d945c4b9a6 60826770 0 2024-01-29 09:24:23 +0000 UTC <nil> <nil> map[] map[kubectl.kubernetes.io/last-applied-configuration:{\"apiVersion\":\"v1\",\"data\":{\"bar\":\"2\",\"foo\":\"1\"},\"kind\":\"ConfigMap\",\"metadata\":{\"annotations\":{},\"name\":\"myconfigmap\",\"namespace\":\"lfabriko\"}}\n] [] [] [{kubectl-client-side-apply Update v1 2024-01-29 09:24:23 +0000 UTC FieldsV1 {\"f:data\":{\".\":{},\"f:bar\":{},\"f:foo\":{}},\"f:metadata\":{\"f:annotations\":{\".\":{},\"f:kubectl.kubernetes.io/last-applied-configuration\":{}}}} }]},Data:map[string]string{bar: 2,foo: 1,},BinaryData:map[string][]byte{},Immutable:nil,}"}
{"level":"info","ts":"2024-01-29T09:28:41Z","logger":"camel-k","msg":"LFAB3 digest v7q7PJwFnLoEd4_wTiIOwkIRVaZHha7n77tCOXz2KH50"}

@squakez
Copy link
Contributor

squakez commented Jan 31, 2024

A part the validate check failure, the rest seems good. However, I think it would be convenient to have some unit test to cover the scenarios we're trying to fix.

Copy link
Contributor

@squakez squakez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the test. However I was meaning more a controller test in order to verify that, when an Integration is provided with the owner reference, then, it is moving correctly among the different phases. Let me make an example. You have the Integration with the configmap in the mount trait spec, this configmap has the owner reference and you verify the controller as it happens for instance in this test:

func TestCamelImportDeployment(t *testing.T) {
- if you can do something with it we'd have the coverage of the issue that was reported and we're sure we're not breaking it again. Alternatively, if you feel more comfortable with e2e, then, it would be also an option, though we should favour unit test whenever it's possible.

@@ -183,7 +183,7 @@ func ComputeForIntegration(integration *v1.Integration, configmaps []*corev1.Con
//StringData with sorted keys
if s.StringData != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stringdata should be avoided as Kubernetes will translate all those value in the correspondent base64 in data. You can remove this part entirely.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for info; also I am not sure if there shouldn't be also binaryData included in digest computation in case of Configmap...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BinaryData for CM would be required as well.

Copy link
Contributor

github-actions bot commented Feb 1, 2024

✔️ Unit test coverage report - coverage increased from 35.6% to 35.7% (+0.1%)

Copy link
Contributor

github-actions bot commented Feb 5, 2024

⚠️ Unit test coverage report - coverage decreased from 35.6% to 35.5% (-0.1%)

@squakez
Copy link
Contributor

squakez commented Feb 5, 2024

@lfabriko any reason why you removed the digest_test.go in the last commit? I think that was still good to make some unit test coverage. In fact, with that change, the coverage decreased. Can you include them back? Having an e2e does not exclude the presence of unit test.

@lfabriko
Copy link
Contributor Author

lfabriko commented Feb 5, 2024

Sure, I thought I should replace it by e2e test.

Copy link
Contributor

github-actions bot commented Feb 5, 2024

✔️ Unit test coverage report - coverage increased from 35.6% to 35.7% (+0.1%)

@lfabriko lfabriko marked this pull request as draft February 5, 2024 11:18
@lfabriko lfabriko marked this pull request as ready for review February 5, 2024 17:37
Copy link
Contributor

github-actions bot commented Feb 6, 2024

✔️ Unit test coverage report - coverage increased from 35.6% to 35.7% (+0.1%)

@lfabriko
Copy link
Contributor Author

lfabriko commented Feb 7, 2024

I observe failed TestRunIncrementalBuildWithDifferentBaseImages.

@lfabriko lfabriko marked this pull request as draft February 7, 2024 10:12
@squakez
Copy link
Contributor

squakez commented Feb 7, 2024

I've restarted the check, maybe it's a flaky one. Please, have a look at the validate error. Locally you can make lint to see what's the problem.

@lfabriko
Copy link
Contributor Author

lfabriko commented Feb 8, 2024

Validation via make lint with golangci-lint version 1.55.2 locally passed for modified files.

@lfabriko lfabriko marked this pull request as ready for review February 8, 2024 00:04
Copy link
Contributor

github-actions bot commented Feb 8, 2024

✔️ Unit test coverage report - coverage increased from 35.6% to 35.8% (+0.2%)

@lfabriko
Copy link
Contributor Author

I observe failed tests TestRunDevMode (in common-it-single-operator-installation) and TestKamelCLIPromote (in common-it-custom-operator-installation); I tried re-running them on lfabriko github (attempts 4-8, branch lfab-ad-5114 rebased on commit #5144) - common-it-single-operator-installation passed in 4, 5, 6, 8; common-it-custom-operator-installation passed in 4, 6.

@squakez squakez merged commit 25f5993 into apache:main Feb 12, 2024
15 checks passed
realMartinez pushed a commit to realMartinez/camel-k that referenced this pull request Feb 29, 2024
realMartinez pushed a commit to realMartinez/camel-k that referenced this pull request Feb 29, 2024
realMartinez pushed a commit to realMartinez/camel-k that referenced this pull request Feb 29, 2024
realMartinez pushed a commit to realMartinez/camel-k that referenced this pull request Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants