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

Deployment configuration and v1alpha2 version #388

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

gazarenkov
Copy link
Member

@gazarenkov gazarenkov commented Jun 20, 2024

Description

This PR includes new way to configure Backstage deployment, now (in contrary to raw config) it is possible to add the changes as a and valid "fragment" of appsv1.deployment object inside Backstage CR and those fields will be merged with default (+raw) configuration, like:

apiVersion: rhdh.redhat.com/v1alpha2
kind: Backstage
metadata:
  name: my-backstage
spec:
  deployment:
    patch:
      spec:
        template:
          metadata:
             labels:
                label1: value1
          spec:
            containers:
              - name: backstage-backend
                 resources:
                    requests:
                        cpu: 250m
                        memory: 256Mi
             - name: my-sidecar
                image: my-sidecar
            volumes:
              - ephemeral:
                  volumeClaimTemplate:
                    spec:
                      storageClassName: "my-special-class"
                name: dynamic-plugins-root

Also, since this addition causes changes in the API, new API version v1alpha2 was added. So, as for Operator versions 0.3.x and 0.4.x (if we consider 3 months release cadency and 6 months API maintain) it will support as minimum both v1alpha1 and v1alpha2 (which become a storage version). After upgrading Operator to 0.3.x the following behaviour expected:

  • existed v1alpha1 CRs are working and shown as v1alpha2
  • both v1alpha1 and v1alpha2 CRs can be added/updated, all shown as v1alpha2

NOTE: v1alpha2 is backward compatible with v1alpha1 w/o data conversion

Openshift NOTE: deployment.patch field won't show up in the "Form view" when creating a CR from the OCP Web. To be able to edit it with ODC use "YAML view".

Which issue(s) does this PR fix or relate to

#352

PR acceptance criteria

How to test changes / Special notes to the reviewer

  • Create v1alpha2 Backstage resource as mentioned above
  • Create resource on 0.2.0 version, then upgrade operator and try to update old and create new resource

Signed-off-by: gazarenkov <[email protected]>
Signed-off-by: gazarenkov <[email protected]>
# Conflicts:
#	bundle/manifests/backstage-operator.clusterserviceversion.yaml
#	config/manifests/bases/backstage-operator.clusterserviceversion.yaml
#	integration_tests/db_test.go
#	integration_tests/default-config_test.go
#	pkg/model/secretfiles_test.go
Signed-off-by: gazarenkov <[email protected]>
Signed-off-by: gazarenkov <[email protected]>
Signed-off-by: gazarenkov <[email protected]>
Copy link

openshift-ci bot commented Jun 20, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from gazarenkov. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link
Contributor

⚠️ Files changed in bundle generation!

Those changes to the operator bundle manifests should have been pushed automatically to your PR branch.
You might also need to manually update the .rhdh/bundle/manifests/rhdh-operator.csv.yaml CSV file accordingly.

.rhdh/bundle/manifests/rhdh-operator.csv.yaml Show resolved Hide resolved
// Defaults to 1.
// +optional
//+kubebuilder:default=1
Replicas *int32 `json:"replicas,omitempty"`
Copy link
Member

@rm3l rm3l Jun 21, 2024

Choose a reason for hiding this comment

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

I guess we need to remove Replicas, Image, and ImagePullSecrets fields from this version, since they are marked as deprecated in v1alpha1 (and the goal is to stop using them)? And the controller would need to manage both versions.
Otherwise, I don't see the point of having a new API Version if we are just adding a new spec.deployment field to the CR (in a backward-compatible manner). We could just add this new field without changing the API version, IMO.
Reference: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api_changes.md#changing-the-api

Copy link
Member

Choose a reason for hiding this comment

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

Also, what would be the behavior if for example both spec.application.replicas and spec.deployment.spec.replicas are set in the CR?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd agree with you in case if do not have GA obligations (indeed "alpha" API allows to do pretty much "whatever you want"). It is definitely simpler way for development. But, it is what it is, and we have to support older API for some time (6 mo).
Anyway, even if we have kind of choice now, I'd consider it as a good exercise for the case when we declare the API as more stable but need to change it, so, I see no reason why not to change the API version if the API is changed :).

Also, what would be the behavior if for example both spec.application.replicas and spec.deployment.spec.replicas are set in the CR?

It is a good point, I think it should be fixed, so new API always wins.

Copy link
Member

Choose a reason for hiding this comment

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

I'd agree with you in case if do not have GA obligations (indeed "alpha" API allows to do pretty much "whatever you want"). It is definitely simpler way for development. But, it is what it is, and we have to support older API for some time (6 mo).

Well, I meant, to remove the deprecated fields from the new v1alpha2 version (not v1alpha1, which I agree still needs to be supported). Otherwise, my point was to say that if we want to keep these deprecated fields in v1alpha2, then maybe v1alpha2 is not needed at all, and the new fields could simply be added to v1alpha1.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure I understand how to support those fields if we remove them. Thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

As documented in https://sdk.operatorframework.io/docs/best-practices/best-practices/, I guess one approach could be to implement CRD conversion here, to automatically convert older v1alpha1 CRs to this new v1alpha2.
But, even if it may be an interesting exercise, we should still be somewhat thoughtful about how we approach this. I still think that we could add the new fields you are suggesting here to the existing v1alpha1; IMO adding new fields to the CRD is a compatible change that should not require a new API version.
We could just document the deprecated ones accordingly.

Copy link
Member Author

Choose a reason for hiding this comment

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

As you could read in the NOTE above: "v1alpha2 is backward compatible with v1alpha1 w/o data conversion"

Not sure what exactly you mean by "been thoughtful", my point is to make it supportable which mean the API version should unequivocally identify the state. So if "v1alpha1" may mean several different (even compatible) combinations of config is not appropriate for supportable (GA) application.

// Custom image to use in all containers (including Init Containers).
// It is your responsibility to make sure the image is from trusted sources and has been validated for security compliance
// +optional
Image *string `json:"image,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

See previous comment..


// Image Pull Secrets to use in all containers (including Init Containers)
// +optional
ImagePullSecrets []string `json:"imagePullSecrets,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

See previous comment..

pkg/model/deployment.go Outdated Show resolved Hide resolved
pkg/model/deployment.go Outdated Show resolved Hide resolved
pkg/model/deployment.go Outdated Show resolved Hide resolved
// Set the Deployment's metadata and|or spec fields you want to override or add.
// Optional.
// +kubebuilder:pruning:PreserveUnknownFields
Deployment *apiextensionsv1.JSON `json:"deployment,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

It looks like this new field won't show up in the "Form view" when creating a CR from the OCP Web Console. I guess because of the field type.

image

Could you investigate how we could display it there? Maybe as a descriptor in the CSV?

Note that it correctly shows up in the "YAML view" with the help of completion..

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it is due to field type, it is unstructured per se.

I think we can create an issue for ODC about it, meantime it should be solved by downstream documentation.

Copy link
Member Author

Choose a reason for hiding this comment

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

added documentation note to PR

pkg/model/db-statefulset.go Outdated Show resolved Hide resolved
# Conflicts:
#	bundle/manifests/backstage-operator.clusterserviceversion.yaml
Signed-off-by: gazarenkov <[email protected]>
…t_patch

# Conflicts:
#	bundle/manifests/backstage-operator.clusterserviceversion.yaml
Copy link
Contributor

github-actions bot commented Jul 8, 2024

⚠️ Files changed in bundle generation!

Those changes to the operator bundle manifests should have been pushed automatically to your PR branch.
You might also need to manually update the .rhdh/bundle/manifests/rhdh-operator.csv.yaml CSV file accordingly.

@openshift-merge-robot
Copy link

PR needs rebase.

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-sigs/prow repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants