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

feat: Render error message condition as json/structured message #3977

Merged
merged 8 commits into from
Jan 24, 2023

Conversation

lburgazzoli
Copy link
Contributor

@lburgazzoli lburgazzoli commented Jan 13, 2023

Fixes #3967

Release Note

NONE

@lburgazzoli lburgazzoli force-pushed the github-3967 branch 3 times, most recently from c2a384e to 2bc4463 Compare January 14, 2023 16:10
@lburgazzoli
Copy link
Contributor Author

@astefanutti I'm experiencing some issues as part of the ci build:

cd pkg/client/camel && go test ./...
# github.com/apache/camel-k/pkg/client/camel/applyconfiguration
Error: applyconfiguration/utils.go:82:19: undefined: v1.HealthCheckResponseApplyConfiguration
Error: applyconfiguration/utils.go:126:19: undefined: v1.PodConditionApplyConfiguration

What is the proper way to generate the client & apply config ?

@astefanutti
Copy link
Member

@astefanutti I'm experiencing some issues as part of the ci build:

cd pkg/client/camel && go test ./...
# github.com/apache/camel-k/pkg/client/camel/applyconfiguration
Error: applyconfiguration/utils.go:82:19: undefined: v1.HealthCheckResponseApplyConfiguration
Error: applyconfiguration/utils.go:126:19: undefined: v1.PodConditionApplyConfiguration

What is the proper way to generate the client & apply config ?

Could you please try generating the client locally by replacing applyconfiguration-gen in the codegen-tools-install target of the Makefile with:

go install github.com/astefanutti/code-generator/cmd/applyconfiguration-gen@pr-144

That should generate the missing types.

This is a temporary "glitch" as a fix is required in code-generator, which will go away as soon as it lands upstream.

@lburgazzoli
Copy link
Contributor Author

mh , looks like it did not help

@astefanutti
Copy link
Member

mh , looks like it did not help

Hum, hasn't make generate created the new types in the pkg/client/camel/applyconfiguration Let me try on my side...

@lburgazzoli
Copy link
Contributor Author

lburgazzoli commented Jan 16, 2023

This is what I see as output for make generate

➜ make generate
Installing k8s.io/code-generator tools with version v0.25.2
#go install k8s.io/code-generator/cmd/applyconfiguration-gen@v0.25.2
go install github.com/astefanutti/code-generator/cmd/applyconfiguration-gen@pr-144
go: finding module for package k8s.io/code-generator/cmd/applyconfiguration-gen/generators
go: finding module for package k8s.io/code-generator/cmd/applyconfiguration-gen/args
go: found k8s.io/code-generator/cmd/applyconfiguration-gen/args in k8s.io/code-generator v0.26.0
go: found k8s.io/code-generator/cmd/applyconfiguration-gen/generators in k8s.io/code-generator v0.26.0
go install k8s.io/code-generator/cmd/client-gen@v0.25.2
go install k8s.io/code-generator/cmd/lister-gen@v0.25.2
go install k8s.io/code-generator/cmd/informer-gen@v0.25.2
./script/gen_client.sh
Generating Go client code...
F0116 11:45:08.040686   39309 main.go:51] Error: Failed executing generator: some packages had errors:
template: /Users/luca-rh/.cache/go/pkg/mod/k8s.io/code-generator@v0.26.0/cmd/applyconfiguration-gen/generators/applyconfiguration.go:220:1:28: executing "/Users/luca-rh/.cache/go/pkg/mod/k8s.io/code-generator@v0.26.0/cmd/applyconfiguration-gen/generators/applyconfiguration.go:220" at <raw>: error calling raw: runtime error: invalid memory address or nil pointer dereference
template: /Users/luca-rh/.cache/go/pkg/mod/k8s.io/code-generator@v0.26.0/cmd/applyconfiguration-gen/generators/applyconfiguration.go:220:1:28: executing "/Users/luca-rh/.cache/go/pkg/mod/k8s.io/code-generator@v0.26.0/cmd/applyconfiguration-gen/generators/applyconfiguration.go:220" at <raw>: error calling raw: runtime error: invalid memory address or nil pointer dereference
./script/gen_crd.sh
./script/gen_doc.sh
Generating API documentation...
Generating CRD API documentation...
I0116 11:45:21.152511   39774 main.go:136] parsing go packages in directory github.com/apache/camel-k/pkg/apis/camel/v1
I0116 11:45:24.586035   39774 main.go:240] using package=github.com/apache/camel-k/pkg/apis/camel/v1
I0116 11:45:24.586054   39774 main.go:240] using package=github.com/apache/camel-k/pkg/apis/camel/v1/trait
W0116 11:45:24.612611   39774 main.go:469] not found external link source for type encoding/xml.Name
I0116 11:45:24.616375   39774 main.go:176] written to ./script/gen_crd/../../docs/modules/ROOT/partials/apis/camel-k-crds.adoc
I0116 11:45:25.044803   39872 main.go:136] parsing go packages in directory github.com/apache/camel-k/pkg/apis/camel/v1alpha1
I0116 11:45:28.453325   39872 main.go:240] using package=github.com/apache/camel-k/pkg/apis/camel/v1alpha1
W0116 11:45:28.462888   39872 main.go:469] not found external link source for type encoding/json.Number
W0116 11:45:28.462939   39872 main.go:469] not found external link source for type encoding/json.Number
W0116 11:45:28.463025   39872 main.go:469] not found external link source for type encoding/json.Number
I0116 11:45:28.464208   39872 main.go:176] written to ./script/gen_crd/../../docs/modules/ROOT/partials/apis/kamelets-crds.adoc
Generating CRD API documentation... Done.
Generating API documentation... done!
Generating traits documentation...
Generating traits documentation... done!
cd pkg/apis/camel && /Users/luca-rh/.cache/go/bin/controller-gen paths="./..." object
cd addons/keda/duck && /Users/luca-rh/.cache/go/bin/controller-gen paths="./..." object
cd addons/strimzi/duck && /Users/luca-rh/.cache/go/bin/controller-gen paths="./..." object
./script/gen_client_strimzi.sh
Generating Go client code for Strimzi addon...

@astefanutti
Copy link
Member

@lburgazzoli Could you please try with:

go install github.com/astefanutti/code-generator/cmd/applyconfiguration-gen@pr-144-install

I've done the required change in that new branch to overcome golang/go#50278, and tested it locally successfully.

@lburgazzoli
Copy link
Contributor Author

Seems to break some other stuffs

go test ./...
# github.com/apache/camel-k/pkg/client/camel/applyconfiguration/camel/v1
pkg/client/camel/applyconfiguration/camel/v1/podcondition.go:45:11: cannot use &value (value of type *"k8s.io/api/core/v1".PodConditionType) as type "k8s.io/api/core/v1".PodConditionType in assignment
pkg/client/camel/applyconfiguration/camel/v1/podcondition.go:53:13: cannot use &value (value of type *"k8s.io/api/core/v1".ConditionStatus) as type "k8s.io/api/core/v1".ConditionStatus in assignment
pkg/client/camel/applyconfiguration/camel/v1/podcondition.go:61:20: cannot use &value (value of type *"k8s.io/apimachinery/pkg/apis/meta/v1".Time) as type "k8s.io/apimachinery/pkg/apis/meta/v1".Time in assignment
pkg/client/camel/applyconfiguration/camel/v1/podcondition.go:69:25: cannot use &value (value of type *"k8s.io/apimachinery/pkg/apis/meta/v1".Time) as type "k8s.io/apimachinery/pkg/apis/meta/v1".Time in assignment
pkg/client/camel/applyconfiguration/camel/v1/podcondition.go:77:13: cannot use &value (value of type *string) as type string in assignment
pkg/client/camel/applyconfiguration/camel/v1/podcondition.go:85:14: cannot use &value (value of type *string) as type string in assignment

And lints:

addons/master/master.go:98:65                                     typecheck      t.Client undefined (type *masterTrait has no field or method Client)
addons/master/master.go:232:45                                    typecheck      t.Client undefined (type *masterTrait has no field or method Client)
addons/resume/resume.go:88:75                                     typecheck      r.Client undefined (type *resumeTrait has no field or method Client)
pkg/controller/build/build_controller.go:165:5                    typecheck      a.InjectClient undefined (type Action has no field or method InjectClient)
pkg/controller/build/build_controller.go:167:5                    typecheck      a.InjectRecorder undefined (type Action has no field or method InjectRecorder)
pkg/controller/integrationkit/integrationkit_controller.go:263:5  typecheck      a.InjectClient undefined (type Action has no field or method InjectClient)
pkg/controller/kamelet/kamelet_controller.go:159:5                typecheck      a.InjectClient undefined (type Action has no field or method InjectClient)
addons/tracing/tracing.go:94:52                                   typecheck      t.Client undefined (type *tracingTrait has no field or method Client)
addons/tracing/tracing.go:99:8                                    typecheck      t.L undefined (type *tracingTrait has no field or method L)
pkg/cmd/root.go:231:24                                            typecheck      invalid operation: cannot compare command._client != nil (operator != not defined on untyped nil)
pkg/controller/integrationplatform/create_test.go:50:4            typecheck      h.InjectClient undefined (type Action has no field or method InjectClient)
pkg/controller/integrationplatform/initialize_test.go:50:4        typecheck      h.InjectClient undefined (type Action has no field or method InjectClient)
pkg/controller/integrationplatform/initialize_test.go:80:4        typecheck      h.InjectClient undefined (type Action has no field or method InjectClient)
pkg/metadata/metadata_capabilities_test.go:50:8                   typecheck      meta.Dependencies undefined (type IntegrationMetadata has no field or method Dependencies)
pkg/metadata/metadata_capabilities_test.go:57:8                   typecheck      meta.RequiredCapabilities undefined (type IntegrationMetadata has no field or method RequiredCapabilities)
pkg/metadata/metadata_dependencies_test.go:62:8                   typecheck      meta.Dependencies undefined (type IntegrationMetadata has no field or method Dependencies)
pkg/metadata/metadata_dependencies_test.go:95:8                   typecheck      meta.Dependencies undefined (type IntegrationMetadata has no field or method Dependencies)
pkg/metadata/metadata_dependencies_test.go:219:22                 typecheck      meta.RequiredCapabilities undefined (type IntegrationMetadata has no field or method RequiredCapabilities)
pkg/metadata/metadata_dependencies_test.go:376:22                 typecheck      meta.RequiredCapabilities undefined (type IntegrationMetadata has no field or method RequiredCapabilities)
pkg/metadata/metadata_http_test.go:48:22                          typecheck      meta.ExposesHTTPServices undefined (type IntegrationMetadata has no field or method ExposesHTTPServices)
pkg/metadata/metadata_http_test.go:49:23                          typecheck      meta.PassiveEndpoints undefined (type IntegrationMetadata has no field or method PassiveEndpoints)
pkg/metadata/metadata_http_test.go:73:22                          typecheck      meta.ExposesHTTPServices undefined (type IntegrationMetadata has no field or method ExposesHTTPServices)
pkg/metadata/metadata_http_test.go:74:22                          typecheck      meta.PassiveEndpoints undefined (type IntegrationMetadata has no field or method PassiveEndpoints)
pkg/metadata/metadata_http_test.go:95:22                          typecheck      meta.ExposesHTTPServices undefined (type IntegrationMetadata has no field or method ExposesHTTPServices)
pkg/metadata/metadata_http_test.go:96:22                          typecheck      meta.PassiveEndpoints undefined (type IntegrationMetadata has no field or method PassiveEndpoints)
pkg/metadata/metadata_uri_test.go:56:30                           typecheck      metadata.FromURIs undefined (type IntegrationMetadata has no field or method FromURIs)
pkg/metadata/metadata_uri_test.go:57:25                           typecheck      metadata.FromURIs undefined (type IntegrationMetadata has no field or method FromURIs)
pkg/metadata/metadata_uri_test.go:58:30                           typecheck      metadata.ToURIs undefined (type IntegrationMetadata has no field or method ToURIs)
pkg/metadata/metadata_uri_test.go:59:25                           typecheck      metadata.ToURIs undefined (type IntegrationMetadata has no field or method ToURIs)
pkg/metadata/metadata_uri_test.go:94:30                           typecheck      metadata.FromURIs undefined (type IntegrationMetadata has no field or method FromURIs)
pkg/metadata/metadata_uri_test.go:96:30                           typecheck      metadata.ToURIs undefined (type IntegrationMetadata has no field or method ToURIs)
pkg/trait/pull_secret.go:74:19                                    typecheck      invalid operation: cannot compare t.Client != nil (operator != not defined on untyped nil)
pkg/trait/trait_catalog.go:59:6                                   typecheck      t.InjectClient undefined (type Trait has no field or method InjectClient)

@astefanutti
Copy link
Member

astefanutti commented Jan 16, 2023

Could you add --input-dirs k8s.io/apimachinery/pkg/apis/meta/v1,k8s.io/api/core/v1 to the list of arguments passed to applyconfiguration-gen in gen_client.sh, as the changes to the Integration types import those packages, and regenerate the client packages?

@lburgazzoli lburgazzoli force-pushed the github-3967 branch 9 times, most recently from 084147b to e80352b Compare January 20, 2023 11:47
@lburgazzoli lburgazzoli marked this pull request as ready for review January 20, 2023 11:49
@lburgazzoli lburgazzoli force-pushed the github-3967 branch 2 times, most recently from 39c55ae to 9d2fa69 Compare January 20, 2023 12:07
@lburgazzoli
Copy link
Contributor Author

@astefanutti @squakez @tadayosi @claudio4j it lacks a test for integration that are scaled > 1, let me know if the test should be part of this pr or can wait for a second iteration.

@lburgazzoli
Copy link
Contributor Author

@astefanutti @squakez @tadayosi @claudio4j it lacks a test for integration that are scaled > 1, let me know if the test should be part of this pr or can wait for a second iteration.

Feel free to track it in a follow up issue and work it later.

#3997


// AffinityApplyConfiguration represents an declarative configuration of the Affinity type for use
// with apply.
type AffinityApplyConfiguration struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is some issue with the autogen. We should not have kubernetes resources here I guess. @astefanutti fyi

Copy link
Member

@astefanutti astefanutti Jan 23, 2023

Choose a reason for hiding this comment

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

I agree it's not ideal to have all these types duplicated. I've giving this another cycle, and it seems there are issues with both embedding and cross-referencing.

@lburgazzoli I know I've been suggesting to embed corev1.PodCondition, but maybe it's not needed in the short term, so we can look into those issues. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As an alternative I can replace the struct with an custom one with the same fields and explicit copy of fields.
Both are fine with me, @astefanutti @squakez cast your vote :)

Copy link
Contributor

Choose a reason for hiding this comment

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

If we don't have all those bunch of duplicated types it would be more maintainable, so, I'd prefer that option.

Copy link
Member

Choose a reason for hiding this comment

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

One alternative that seems to work is to not inline the corev1.PodCondition, i.e. adding a field, and remove metav1 and corev1 from the code-generator input dirs. That way the API still has the corresponding info, but the generated apply configurations do no contain any duplicate, and instead refer to the API rather than the apply configurations, which is acceptable IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, will try that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done, please have a look at the latest commits (it is a little bit weird as there is a Pod nested field in the PodCondition (if you have better names, please suggest)

Copy link
Member

@astefanutti astefanutti Jan 23, 2023

Choose a reason for hiding this comment

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

Maybe re-naming the field to Readiness or Ready would make it clear it's the ready condition from the Pod that's provided?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@lburgazzoli lburgazzoli force-pushed the github-3967 branch 3 times, most recently from 4181822 to 1923898 Compare January 23, 2023 13:29
@lburgazzoli
Copy link
Contributor Author

Note, a number of tests are failing because of:

  no matching manifest for linux/amd64 in the manifest list entries

Copy link
Member

@astefanutti astefanutti left a comment

Choose a reason for hiding this comment

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

Looks great!

script/gen_client_strimzi.sh Outdated Show resolved Hide resolved
pkg/controller/integration/monitor.go Outdated Show resolved Hide resolved
- support for MAVEN_CMD env var as camel-k does
- run maven in batch mode to avoid including ASCII escaping chars in the
  error message which could cause the test to fail in some evironments
I've removed some expectation as based on timing an likely to randomly
fail.
- remove goroutine for build related test as not needed
- added waiting group to wait for async tasks completion
Copy link
Member

@tadayosi tadayosi left a comment

Choose a reason for hiding this comment

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

LGMT. Thanks!

@lburgazzoli
Copy link
Contributor Author

@squakez @astefanutti anything missing or ok to merge ?

@astefanutti
Copy link
Member

@squakez @astefanutti anything missing or ok to merge ?

I'd be inclined to have the change to temurin as default base image (131915b) done in a separate PR to make it more visible in the release note and ease backport. Other than that, it's good to go 👍🏼.

@lburgazzoli
Copy link
Contributor Author

let see if I can work on something

@squakez squakez mentioned this pull request Jan 24, 2023
@lburgazzoli
Copy link
Contributor Author

@astefanutti opened #4003 (it is actually made by 3 commits, I can squash them if needed)

@astefanutti
Copy link
Member

@astefanutti opened #4003 (it is actually made by 3 commits, I can squash them if needed)

Awesome! Let's wait CI to pass for #4003, so we can merge it and have that one rebased on top.

@lburgazzoli lburgazzoli merged commit 30a82e5 into apache:main Jan 24, 2023
@lburgazzoli lburgazzoli deleted the github-3967 branch January 24, 2023 11:49
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.

Render error message condition as json/structured message
5 participants