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

Serializing Subscription resources without including "status" field? #275

Open
larsks opened this issue Dec 24, 2022 · 0 comments
Open

Serializing Subscription resources without including "status" field? #275

larsks opened this issue Dec 24, 2022 · 0 comments

Comments

@larsks
Copy link

larsks commented Dec 24, 2022

I would like to serialize a Subscription resource to YAML using code like this:

	subscription := operatorsv1alpha1.Subscription{
		TypeMeta: metav1.TypeMeta{
			APIVersion: operatorsv1alpha1.SubscriptionCRDAPIVersion,
			Kind:       operatorsv1alpha1.SubscriptionKind,
		},
		ObjectMeta: metav1.ObjectMeta{
			Namespace: namespaceName,
			Name:      pkg.Name,
		},
		Spec: &operatorsv1alpha1.SubscriptionSpec{
			Package:                pkg.Name,
			Channel:                channel.Name,
			InstallPlanApproval:    operatorsv1alpha1.Approval(subscribeFlags.Approval),
			CatalogSource:          pkg.Status.CatalogSource,
			CatalogSourceNamespace: pkg.Status.CatalogSourceNamespace,
		},
	}

	operatorsv1alpha1.AddToScheme(scheme.Scheme)
	corev1.AddToScheme(scheme.Scheme)

	serializer := json.NewSerializerWithOptions(
		json.DefaultMetaFactory, scheme.Scheme, scheme.Scheme,
		json.SerializerOptions{
			Pretty: true,
			Yaml:   true,
			Strict: true,
		})

	if err := serializer.Encode(&subscription, os.Stdout); err != nil {
		return err
	}

This works, except that operator-framework/api defines a Subcription resource like this:

type Subscription struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata"`

	Spec *SubscriptionSpec `json:"spec"`
	// +optional
	Status SubscriptionStatus `json:"status"`
}

Which means that the serialized output always includes a status element with a null status.lastUpdated field. Submitting the serialized manifest fails with:

error: error validating "STDIN": error validating data: ValidationError(Subscription.status): missing required field "lastUpdated" in com.coreos.operators.v1alpha1.Subscription.status; if you choose to ignore these errors, turn validation off with --validate=false

Is there a canonical method for serializing these resources without including the status field? Is there a reason that the Subscription type isn't defined like:

type Subscription struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata"`

	Spec *SubscriptionSpec `json:"spec"`
	// +optional
	Status *SubscriptionStatus `json:"status,omitempty"`
}

If the Status field were nil-able, it would be easy to get the desired output.

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

No branches or pull requests

1 participant