controller-tools icon indicating copy to clipboard operation
controller-tools copied to clipboard

Error when using json.RawMessage - string vs object

Open armsnyder opened this issue 3 years ago • 5 comments

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

armsnyder avatar Nov 09 '21 20:11 armsnyder

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-triage-robot avatar Feb 07 '22 21:02 k8s-triage-robot

/remove-lifecycle stale

armsnyder avatar Feb 07 '22 21:02 armsnyder

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

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

seba-ban avatar Apr 06 '22 10:04 seba-ban

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-triage-robot avatar Jul 05 '22 11:07 k8s-triage-robot

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-triage-robot avatar Aug 04 '22 12:08 k8s-triage-robot

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-triage-robot avatar Sep 03 '22 13:09 k8s-triage-robot

@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.

k8s-ci-robot avatar Sep 03 '22 13:09 k8s-ci-robot

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

kitianFresh avatar May 17 '24 07:05 kitianFresh