Skip to content

Error when using json.RawMessage - string vs object #637

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

Closed
armsnyder opened this issue Nov 9, 2021 · 8 comments
Closed

Error when using json.RawMessage - string vs object #637

armsnyder opened this issue Nov 9, 2021 · 8 comments
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.

Comments

@armsnyder
Copy link

armsnyder commented Nov 9, 2021

Overview

Continuing from bug report #533 which was likely fixed and then resurfaced.

Using controller-gen v0.6.2 you get an error when using json.RawMessage to represent unstructured fields.

(As a note, I would rather be able to use the map[string]interface{} type, which would make this bug a non-issue for me, see #636 😉 )

Repro 1 - RawMessage has string type by default

// BackendSpec defines the desired state of Backend
type BackendSpec struct {
	// +kubebuilder:pruning:PreserveUnknownFields
	DeploymentTemplate json.RawMessage `json:"deploymentTemplate"`
}

Expected:

spec:
  description: BackendSpec defines the desired state of Backend
  properties:
    deploymentTemplate:
      description: The template for created deployments.
      type: object
      x-kubernetes-preserve-unknown-fields: true

Actual:

spec:
  description: BackendSpec defines the desired state of Backend
  properties:
    deploymentTemplate:
      description: The template for created deployments.
      format: byte
      type: string
      x-kubernetes-preserve-unknown-fields: true

Repro 2 - Explicit validation:Type=object causes error

// BackendSpec defines the desired state of Backend
type BackendSpec struct {
	// +kubebuilder:pruning:PreserveUnknownFields
	// +kubebuilder:validation:Type=object
	DeploymentTemplate json.RawMessage `json:"deploymentTemplate"`
}

Expected:

spec:
  description: BackendSpec defines the desired state of Backend
  properties:
    deploymentTemplate:
      description: The template for created deployments.
      type: object
      x-kubernetes-preserve-unknown-fields: true

Actual (error):

api/v1alpha1:-: conflicting types in allOf branches in schema: string vs object

Versions

controller-gen v0.6.2
k8s.io/apimachinery v0.22.2
k8s.io/client-go v0.22.2
sigs.k8s.io/controller-runtime v0.10.2

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Feb 7, 2022
@armsnyder
Copy link
Author

/remove-lifecycle stale

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Feb 7, 2022
@seba-ban
Copy link

seba-ban commented Apr 6, 2022

Adding // +kubebuilder:validation:Schemaless worked for me:

// +kubebuilder:validation:Schemaless
// +kubebuilder:pruning:PreserveUnknownFields
// +kubebuilder:validation:Type=object

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jul 5, 2022
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Aug 4, 2022
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue or PR with /reopen
  • Mark this issue or PR as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close

@k8s-ci-robot
Copy link
Contributor

@k8s-triage-robot: Closing this issue.

In response to this:

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue or PR with /reopen
  • Mark this issue or PR as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

akutz added a commit to akutz/vm-operator that referenced this issue Jan 5, 2023
This patch updates the VMClass.Spec.ConfigSpec to be json.RawMessage,
which is similar to runtime.RawExtension, but has no opinion about
being a runtime.Object.

Per kubernetes-sigs/controller-tools#637,
it was necessary to decorate the field with the following kubebuilder
annotations to force the wire protocol to be an object:

	// +kubebuilder:validation:Schemaless
	// +kubebuilder:validation:Type=object
	// +kubebuilder:pruning:PreserveUnknownFields
akutz added a commit to akutz/vm-operator that referenced this issue Jan 5, 2023
This patch updates the VMClass.Spec.ConfigSpec to be json.RawMessage,
which is similar to runtime.RawExtension, but has no opinion about
being a runtime.Object.

Per kubernetes-sigs/controller-tools#637,
it was necessary to decorate the field with the following kubebuilder
annotations to force the wire protocol to be an object:

	// +kubebuilder:validation:Schemaless
	// +kubebuilder:validation:Type=object
	// +kubebuilder:pruning:PreserveUnknownFields
akutz added a commit to akutz/vm-operator that referenced this issue Jan 5, 2023
This patch updates the VMClass.Spec.ConfigSpec to be json.RawMessage,
which is similar to runtime.RawExtension, but has no opinion about
being a runtime.Object.

Per kubernetes-sigs/controller-tools#637,
it was necessary to decorate the field with the following kubebuilder
annotations to force the wire protocol to be an object:

	// +kubebuilder:validation:Schemaless
	// +kubebuilder:validation:Type=object
	// +kubebuilder:pruning:PreserveUnknownFields
@kitianFresh
Copy link

how to solve this? is the k8s version and controller version conflict?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.
Projects
None yet
Development

No branches or pull requests

5 participants