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

MGMT-8571: Deploy the image service as a stateful set #3067

Merged

Conversation

carbonin
Copy link
Member

@carbonin carbonin commented Dec 16, 2021

Description

Previously, when deploying the image service as a deployment, we were
writing the template images to the pod filesystem. This isn't good for
performance or the health of the node we're running on.

Because of this the image service now will run as a stateful set and
request a PV for the data directory. If information for a new PVC has
been provided in the agentserviceconfig. If no PVC information was
provided an emptydir volume is used.

Changing the storage template of a stateful set requires that we delete
and recreate the entire statefulset. This means that, in this case, we
can't use controllerutil.CreateOrUpdate.

This commit creates a separate function to reconcile just this
statefulset which has a section very similar to create or update but with
some additional logic around when we can do a normal update and when we
need to recreate the statefulset.

This also adds some logic to remove the old image service deployment.
This is required for upgrade. Note the specific error handling which
ensures that we only delete the deployment if we successfully
reconciled (created, most likely) the statefulset to replace it.

A finalizer is added to the statefulset to ensure we remove the PVC as
we need to support resizing the volume which will mean claiming a new
PV.

A finalizer is also added to the agentserviceconfig object to ensure we
clean up the image-service PVCs in the case that the agentserviceconfig
is deleted directly.

List all the issues related to this PR

https://issues.redhat.com/browse/MGMT-8571

  • New Feature
  • Bug fix
  • Tests
  • Documentation
  • CI/CD

What environments does this code impact?

  • Automation (CI, tools, etc)
  • Cloud
  • Operator Managed Deployments
  • None

How was this code tested?

  • assisted-test-infra environment
  • dev-scripts environment
  • Reviewer's test appreciated
  • Waiting for CI to do a full test run
  • Manual (Elaborate on how it was tested)
  • No tests needed\

Deployed the operator locally to a crc cluster using operator-sdk run bundle.
Saw the image service created as a stateful set with the PV attached properly.
Created an infra-env and downloaded the image.

Assignees

/cc @avishayt
/cc @pawanpinjarkar

Checklist

  • Title and description added to both, commit and PR.
  • Relevant issues have been associated (see [CONTRIBUTING] guide)
  • Reviewers have been listed
  • This change does not require a documentation update (docstring, docs, README, etc)
  • Does this change include unit-tests (note that code changes require unit-tests)

Reviewers Checklist

  • Are the title and description (in both PR and commit) meaningful and clear?
  • Is there a bug required (and linked) for this change?
  • Should this PR be backported?

@openshift-ci openshift-ci bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. api-review Categorizes an issue or PR as actively needing an API review. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Dec 16, 2021
@carbonin carbonin force-pushed the stateful_image_service branch 2 times, most recently from a204185 to 83277b7 Compare December 17, 2021 14:05
@openshift-ci openshift-ci bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Dec 17, 2021
@carbonin
Copy link
Member Author

/hold

committed some stuff I shouldn't have

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Dec 17, 2021
@carbonin
Copy link
Member Author

/test ?

@openshift-ci
Copy link

openshift-ci bot commented Dec 17, 2021

@carbonin: The following commands are available to trigger required jobs:

  • /test bundle-ci-index-assisted-service-bundle
  • /test bundle-images
  • /test ci-index
  • /test e2e-metal-assisted
  • /test e2e-metal-assisted-ipv6
  • /test e2e-metal-assisted-kube-api
  • /test e2e-metal-assisted-olm
  • /test e2e-metal-assisted-operator-ztp
  • /test images
  • /test lint
  • /test subsystem-aws
  • /test subsystem-kubeapi-aws
  • /test unit-test

The following commands are available to trigger optional jobs:

  • /test e2e-ai-operator-ztp-ipv4v6-3masters-ocp-48
  • /test e2e-ai-operator-ztp-ipv4v6-3masters-ocp-49
  • /test e2e-ai-operator-ztp-ipv4v6-sno-ocp-48
  • /test e2e-ai-operator-ztp-ipv4v6-sno-ocp-49
  • /test e2e-metal-assisted-day2
  • /test e2e-metal-assisted-ipv4v6
  • /test e2e-metal-assisted-kube-api-late-binding-single-node
  • /test e2e-metal-assisted-kube-api-late-unbinding-ipv4-single-node
  • /test e2e-metal-assisted-multi-version
  • /test e2e-metal-assisted-networking
  • /test e2e-metal-assisted-none
  • /test e2e-metal-assisted-operator-disconnected
  • /test e2e-metal-assisted-operator-ztp-multinode-spoke
  • /test e2e-metal-assisted-single-node
  • /test e2e-metal-assisted-tpmv2

Use /test all to run the following jobs that were automatically triggered:

  • pull-ci-openshift-assisted-service-master-bundle-ci-index-assisted-service-bundle
  • pull-ci-openshift-assisted-service-master-bundle-images
  • pull-ci-openshift-assisted-service-master-ci-index
  • pull-ci-openshift-assisted-service-master-e2e-metal-assisted
  • pull-ci-openshift-assisted-service-master-e2e-metal-assisted-kube-api
  • pull-ci-openshift-assisted-service-master-e2e-metal-assisted-operator-ztp
  • pull-ci-openshift-assisted-service-master-images
  • pull-ci-openshift-assisted-service-master-lint
  • pull-ci-openshift-assisted-service-master-subsystem-aws
  • pull-ci-openshift-assisted-service-master-subsystem-kubeapi-aws
  • pull-ci-openshift-assisted-service-master-unit-test

In response to this:

/test ?

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.

@carbonin
Copy link
Member Author

carbonin commented Dec 17, 2021

Rebased out what I shouldn't have committed, but leaving the hold as the upgrade doesn't work.
Two things still need to be sorted out:

  1. Adding a new mandatory field to our agent-service-config CRD is causing the CSV to never complete the upgrade
    • If we want to keep the field (imageStorage) mandatory then I think we'll need a new major version.
    • Even with a new major version I'm not sure how the upgrade will look for customers
    • If we make the field optional (and maybe use an EmptyDir volume if it's not specified) then maybe we can get away with a minor version bump
    • Even then I'll need to test the case where someone goes from emptyDir to a PVC to make sure that works well.
  2. When the upgrade does work, the operator as it exists now will leave the old image service deployment around; we need to remove this.
    • There isn't really anything in the operator-framework or OLM that will help us with this so assuming we want to keep our upgrade graph unconstrained then we'll need to write out some code to remove the deployment if we see it as a part of the reconcile loop.

@carbonin
Copy link
Member Author

Unsure if we want to wait to merge this before sorting out #3067 (comment), so I'll leave the hold for now.

@carbonin
Copy link
Member Author

  • If we make the field optional (and maybe use an EmptyDir volume if it's not specified) then maybe we can get away with a minor version bump
  • Even then I'll need to test the case where someone goes from emptyDir to a PVC to make sure that works well.

Tested this case out and it doesn't look like it's going to work unless we want to delete and re-create the entire statefulset when the storage information is updated. Specifically I got this error when I changed the CR to include storage information after an upgrade:

"StatefulSet.apps "assisted-image-service" is invalid: spec: Forbidden: updates to statefulset spec for fields other than 'replicas', 'template', and 'updateStrategy' are forbidden"

@mhrivnak any advice here? Is there some PVC spec that would be safe for us to default to? I could base the size on the number of osImage entries, but I'm sure there are environments that will require more than just the size requirement.

@mhrivnak
Copy link
Member

"StatefulSet.apps "assisted-image-service" is invalid: spec: Forbidden: updates to statefulset spec for fields other than 'replicas', 'template', and 'updateStrategy' are forbidden"

@mhrivnak any advice here? Is there some PVC spec that would be safe for us to default to? I could base the size on the number of osImage entries, but I'm sure there are environments that will require more than just the size requirement.

The statefulset has to be deleted and recreated to change the storage details. That's something the operator can automate. Then we can just expose settings like size on our CR. Maybe we can extrapolate from our previous recommendations what might be a sensible default or recommended size?

Is it important to migrate data in this case? Or can the new volume start empty?

@carbonin
Copy link
Member Author

carbonin commented Dec 22, 2021

The statefulset has to be deleted and recreated to change the storage details. That's something the operator can automate.

Okay, so it makes sense to recreate the stateful set 👍

Then we can just expose settings like size on our CR. Maybe we can extrapolate from our previous recommendations what might be a sensible default or recommended size?

If we're going to rebuild the whole stateful set then I don't think we need to change how we ask users to specify the storage details. We could validate that the size is over some reasonable minimum, but I think that's probably a different conversation.

Is it important to migrate data in this case? Or can the new volume start empty?

No, the data itself will be recreated.

Copy link
Contributor

@flaper87 flaper87 left a comment

Choose a reason for hiding this comment

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

@carbonin could you elaborate (maybe in the PR description) on the choice of using StatefulSet vs Deployment?

@carbonin
Copy link
Member Author

carbonin commented Jan 4, 2022

Updated with a bit more detail @flaper87. Let me know if something still isn't clear.

@carbonin carbonin changed the title MGMT-8571: Deploy the image service as a stateful set [WIP] MGMT-8571: Deploy the image service as a stateful set Jan 13, 2022
@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jan 13, 2022
@carbonin
Copy link
Member Author

Marking this as WIP.
Added a few comments in the code so I can keep track of what I still need to test and handle.

With this I was able to deploy the statefulset and update the agentserviceconfig CR to add storage and have the statefulset recreate successfully.

This should mean that we can keep the storage value in the CR optional which will unstick upgrade. Now I need to test a full upgrade from an older (master) version of the operator to the one in this branch which will move us from a deployment to a statefulset.

@carbonin carbonin force-pushed the stateful_image_service branch 2 times, most recently from f03ae30 to 4b13872 Compare January 19, 2022 21:59
@openshift-ci openshift-ci bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jan 19, 2022
This also stops trying to monitor the image service as a deployment and
reduces the number of `Get` calls by only fetching each deployment once
per loop rather than re-fetching it for each condition we want to check.
Previously, when deploying the image service as a deployment, we were
writing the template images to the pod filesystem. This isn't good for
performance or the health of the node we're running on.

Because of this the image service now will run as a stateful set and
request a PV for the data directory. If information for a new PVC has
been provided in the agentserviceconfig. If no PVC information was
provided an emptydir volume is used.

Changing the storage template of a stateful set requires that we delete
and recreate the entire statefulset. This means that, in this case, we
can't use controllerutil.CreateOrUpdate.

This commit creates a separate function to reconcile just this
statefulset which has a section very similar to create or update but with
some additional logic around when we can do a normal update and when we
need to recreate the statefulset.

This also adds some logic to remove the old image service deployment.
This is required for upgrade. Note the specific error handling which
ensures that we only delete the deployment if we successfully
reconciled (created, most likely) the statefulset to replace it.

A finalizer is added to the statefulset to ensure we remove the PVC as
we need to support resizing the volume which will mean claiming a new
PV.

A finalizer is also added to the agentserviceconfig object to ensure we
clean up the image-service PVCs in the case that the agentserviceconfig
is deleted directly.

https://issues.redhat.com/browse/MGMT-8571
@carbonin
Copy link
Member Author

carbonin commented Mar 9, 2022

/override ci/prow/e2e-metal-assisted-operator-ztp

This is broken everywhere

@openshift-ci
Copy link

openshift-ci bot commented Mar 9, 2022

@carbonin: Overrode contexts on behalf of carbonin: ci/prow/e2e-metal-assisted-operator-ztp

In response to this:

/override ci/prow/e2e-metal-assisted-operator-ztp

This is broken everywhere

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.

@carbonin
Copy link
Member Author

carbonin commented Mar 9, 2022

/retest

Errors don't look related to this PR.

@openshift-ci
Copy link

openshift-ci bot commented Mar 9, 2022

@carbonin: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/e2e-assisted-capi-provider-agent-hypershift b206f2e link false /test e2e-assisted-capi-provider-agent-hypershift
ci/prow/e2e-metal-assisted-kube-api b206f2e link false /test e2e-metal-assisted-kube-api

Full PR test history. Your PR dashboard.

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. I understand the commands that are listed here.

@carbonin carbonin requested a review from mhrivnak March 10, 2022 13:19
@carbonin
Copy link
Member Author

/test e2e-ai-operator-ztp-ipv4v6-3masters-ocp-49

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Mar 10, 2022
@mhrivnak
Copy link
Member

/lgtm

@openshift-ci
Copy link

openshift-ci bot commented Mar 10, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: carbonin, filanov, mhrivnak

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

The pull request process is described 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

@openshift-merge-robot openshift-merge-robot merged commit c77aa81 into openshift:master Mar 10, 2022
mmartinv pushed a commit to mmartinv/assisted-service that referenced this pull request Mar 11, 2022
* MGMT-8571: add optional image storage to agent service config

* MGMT-8571: add image storage to operator deploy script and docs

* MGMT-8571: Refactor monitoring into a separate method

This also stops trying to monitor the image service as a deployment and
reduces the number of `Get` calls by only fetching each deployment once
per loop rather than re-fetching it for each condition we want to check.

* MGMT-8571: Deploy the image service as a stateful set

Previously, when deploying the image service as a deployment, we were
writing the template images to the pod filesystem. This isn't good for
performance or the health of the node we're running on.

Because of this the image service now will run as a stateful set and
request a PV for the data directory. If information for a new PVC has
been provided in the agentserviceconfig. If no PVC information was
provided an emptydir volume is used.

Changing the storage template of a stateful set requires that we delete
and recreate the entire statefulset. This means that, in this case, we
can't use controllerutil.CreateOrUpdate.

This commit creates a separate function to reconcile just this
statefulset which has a section very similar to create or update but with
some additional logic around when we can do a normal update and when we
need to recreate the statefulset.

This also adds some logic to remove the old image service deployment.
This is required for upgrade. Note the specific error handling which
ensures that we only delete the deployment if we successfully
reconciled (created, most likely) the statefulset to replace it.

A finalizer is added to the statefulset to ensure we remove the PVC as
we need to support resizing the volume which will mean claiming a new
PV.

A finalizer is also added to the agentserviceconfig object to ensure we
clean up the image-service PVCs in the case that the agentserviceconfig
is deleted directly.

https://issues.redhat.com/browse/MGMT-8571
mresvanis pushed a commit to mresvanis/assisted-service that referenced this pull request Mar 14, 2022
* MGMT-8571: add optional image storage to agent service config

* MGMT-8571: add image storage to operator deploy script and docs

* MGMT-8571: Refactor monitoring into a separate method

This also stops trying to monitor the image service as a deployment and
reduces the number of `Get` calls by only fetching each deployment once
per loop rather than re-fetching it for each condition we want to check.

* MGMT-8571: Deploy the image service as a stateful set

Previously, when deploying the image service as a deployment, we were
writing the template images to the pod filesystem. This isn't good for
performance or the health of the node we're running on.

Because of this the image service now will run as a stateful set and
request a PV for the data directory. If information for a new PVC has
been provided in the agentserviceconfig. If no PVC information was
provided an emptydir volume is used.

Changing the storage template of a stateful set requires that we delete
and recreate the entire statefulset. This means that, in this case, we
can't use controllerutil.CreateOrUpdate.

This commit creates a separate function to reconcile just this
statefulset which has a section very similar to create or update but with
some additional logic around when we can do a normal update and when we
need to recreate the statefulset.

This also adds some logic to remove the old image service deployment.
This is required for upgrade. Note the specific error handling which
ensures that we only delete the deployment if we successfully
reconciled (created, most likely) the statefulset to replace it.

A finalizer is added to the statefulset to ensure we remove the PVC as
we need to support resizing the volume which will mean claiming a new
PV.

A finalizer is also added to the agentserviceconfig object to ensure we
clean up the image-service PVCs in the case that the agentserviceconfig
is deleted directly.

https://issues.redhat.com/browse/MGMT-8571
mkowalski added a commit to mkowalski/metal3-dev-scripts that referenced this pull request Mar 16, 2022
With openshift/assisted-service#3067 we have
introduced an `imageStorage` configuration option that needs to be set
in the AgentServiceConfig for Infrastructure Operator.

This PR adds the configuration, so that `make assisted` target can
deploy the operator seamlessly.
mkowalski added a commit to mkowalski/metal3-dev-scripts that referenced this pull request Apr 27, 2022
With openshift/assisted-service#3067 we have
introduced an `imageStorage` configuration option that needs to be set
in the AgentServiceConfig for Infrastructure Operator.

This PR adds the configuration, so that `make assisted` target can
deploy the operator seamlessly.
mkowalski added a commit to mkowalski/metal3-dev-scripts that referenced this pull request Aug 24, 2022
With openshift/assisted-service#3067 we have
introduced an `imageStorage` configuration option that needs to be set
in the AgentServiceConfig for Infrastructure Operator.

This PR adds the configuration, so that `make assisted` target can
deploy the operator seamlessly.
flaper87 pushed a commit to flaper87/assisted-service that referenced this pull request Sep 21, 2022
* MGMT-8571: add optional image storage to agent service config

* MGMT-8571: add image storage to operator deploy script and docs

* MGMT-8571: Refactor monitoring into a separate method

This also stops trying to monitor the image service as a deployment and
reduces the number of `Get` calls by only fetching each deployment once
per loop rather than re-fetching it for each condition we want to check.

* MGMT-8571: Deploy the image service as a stateful set

Previously, when deploying the image service as a deployment, we were
writing the template images to the pod filesystem. This isn't good for
performance or the health of the node we're running on.

Because of this the image service now will run as a stateful set and
request a PV for the data directory. If information for a new PVC has
been provided in the agentserviceconfig. If no PVC information was
provided an emptydir volume is used.

Changing the storage template of a stateful set requires that we delete
and recreate the entire statefulset. This means that, in this case, we
can't use controllerutil.CreateOrUpdate.

This commit creates a separate function to reconcile just this
statefulset which has a section very similar to create or update but with
some additional logic around when we can do a normal update and when we
need to recreate the statefulset.

This also adds some logic to remove the old image service deployment.
This is required for upgrade. Note the specific error handling which
ensures that we only delete the deployment if we successfully
reconciled (created, most likely) the statefulset to replace it.

A finalizer is added to the statefulset to ensure we remove the PVC as
we need to support resizing the volume which will mean claiming a new
PV.

A finalizer is also added to the agentserviceconfig object to ensure we
clean up the image-service PVCs in the case that the agentserviceconfig
is deleted directly.

https://issues.redhat.com/browse/MGMT-8571
@carbonin carbonin deleted the stateful_image_service branch November 8, 2022 13:55
mkowalski added a commit to mkowalski/metal3-dev-scripts that referenced this pull request Dec 6, 2022
With openshift/assisted-service#3067 we have
introduced an `imageStorage` configuration option that needs to be set
in the AgentServiceConfig for Infrastructure Operator.

This PR adds the configuration, so that `make assisted` target can
deploy the operator seamlessly.
danielerez pushed a commit to danielerez/assisted-service that referenced this pull request Oct 15, 2023
* MGMT-8571: add optional image storage to agent service config

* MGMT-8571: add image storage to operator deploy script and docs

* MGMT-8571: Refactor monitoring into a separate method

This also stops trying to monitor the image service as a deployment and
reduces the number of `Get` calls by only fetching each deployment once
per loop rather than re-fetching it for each condition we want to check.

* MGMT-8571: Deploy the image service as a stateful set

Previously, when deploying the image service as a deployment, we were
writing the template images to the pod filesystem. This isn't good for
performance or the health of the node we're running on.

Because of this the image service now will run as a stateful set and
request a PV for the data directory. If information for a new PVC has
been provided in the agentserviceconfig. If no PVC information was
provided an emptydir volume is used.

Changing the storage template of a stateful set requires that we delete
and recreate the entire statefulset. This means that, in this case, we
can't use controllerutil.CreateOrUpdate.

This commit creates a separate function to reconcile just this
statefulset which has a section very similar to create or update but with
some additional logic around when we can do a normal update and when we
need to recreate the statefulset.

This also adds some logic to remove the old image service deployment.
This is required for upgrade. Note the specific error handling which
ensures that we only delete the deployment if we successfully
reconciled (created, most likely) the statefulset to replace it.

A finalizer is added to the statefulset to ensure we remove the PVC as
we need to support resizing the volume which will mean claiming a new
PV.

A finalizer is also added to the agentserviceconfig object to ensure we
clean up the image-service PVCs in the case that the agentserviceconfig
is deleted directly.

https://issues.redhat.com/browse/MGMT-8571
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-review Categorizes an issue or PR as actively needing an API review. approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants