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

🐛 Compress components manifests if they don't fit in the configmap #192

Merged
merged 3 commits into from
Jul 25, 2023

Conversation

Fedosin
Copy link
Contributor

@Fedosin Fedosin commented Jul 19, 2023

What this PR does / why we need it:
By default we download capi provider manifests from the provided URL and store it in a confimap to reuse later. Currently there is a limit on the configmap size, which is 1mb. If we the manifests size is bigger then the installation process fails.

To avoid it we will compress manifests if they can't be stored in the configmap directly.
Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #20

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jul 19, 2023
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jul 19, 2023
@Fedosin Fedosin changed the title 🐛 Compress components manifests if they don't fit the configmap 🐛 Compress components manifests if they don't fit шт the configmap Jul 20, 2023
@Fedosin Fedosin changed the title 🐛 Compress components manifests if they don't fit шт the configmap 🐛 Compress components manifests if they don't fit in the configmap Jul 20, 2023
// getComponentsData returns components data based on if it's compressed or not.
func getComponentsData(cm corev1.ConfigMap) (string, error) {
// Data is not compressed, return it immediately.
if cm.GetAnnotations()[compressedAnnotation] != "true" {
Copy link
Contributor

Choose a reason for hiding this comment

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

We should also add docs about this annotation, If users compress manifests manually and try to use them in an air-gapped scenario, this annotation has to be set on the configmap.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey! I added the documentation, that describes this process for air-gapped environments.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 21, 2023
Copy link
Member

@furkatgofurov7 furkatgofurov7 left a comment

Choose a reason for hiding this comment

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

Thank you!

Overall LGTM, small nit and not blocking question

internal/controller/manifests_downloader.go Outdated Show resolved Hide resolved
return components, nil
}

// Otherwise we have to decompress the data first.
Copy link
Member

@furkatgofurov7 furkatgofurov7 Jul 21, 2023

Choose a reason for hiding this comment

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

Q. to better understand this logic: what is the use case when it is already compressed and why we need to decompress in that case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the normal workflow, when we create a provider for the first time, we download manifests from the provided URL and store them in a configmap to reuse later. Unfortunately, there is a size limit (1MiB) on the configmap in kubernetes, and for some providers we can't store there manifests directly.

Here is an example of capi provider that has infrastructure-components.yaml file exceeding 1MiB: https://github.com/oracle/cluster-api-provider-oci/releases/tag/v0.12.0

The error looks like this:

E0718 10:19:28.002488       1 controller.go:329]  "msg"="Reconciler error" "error"="failed to create config map for provider \"oci\": ConfigMap \"infrastructure-oci-v0.12.0\" is invalid: []: Too long: must have at most 1048576 bytes" "InfrastructureProvider"={"name":"oci","namespace":"cluster-api"} "controller"="infrastructureprovider" "controllerGroup"="operator.cluster.x-k8s.io" "controllerKind"="InfrastructureProvider" "name"="oci" "namespace"="cluster-api" "reconcileID"="
3530ba70-285c-4a14-997b-5bdfc092c973

To workaround this we put compressed data in the configmap, which is 10 times smaller than the original. Later, when we generate clusterctl provider repository in the "load" phase, we decompress it and use as before.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks @Fedosin!

@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 21, 2023
Fedosin added 3 commits July 21, 2023 15:57
By default we download capi provider manifests from a provided URL
and store it in a confimap to reuse later. Currently there is a limit
on the configmap size, which is 1mb. If we the manifests size is bigger,
then the installation process fails.

To avoid it we will compress manifests if they can't be stored in the
configmap directly.
Copy link
Contributor

@alexander-demicev alexander-demicev left a comment

Choose a reason for hiding this comment

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

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alexander-demicev

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 24, 2023
componentsConfigMapKey = "components"
)

var _ = Describe("Create and delete a provider with manifests that don't fit the configmap", func() {
Copy link
Contributor

@alexander-demicev alexander-demicev Jul 24, 2023

Choose a reason for hiding this comment

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

can we also have a test where we supply an already compressed configmap? Can be done in a follow-up PR

Copy link
Member

@furkatgofurov7 furkatgofurov7 left a comment

Choose a reason for hiding this comment

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

/lgtm

2. Create a configmap manifest from the archived data

```sh
kubectl create configmap v1.9.3 --namespace=capz-system --from-file=components=components.gz --from-file=metadata=metadata.yaml --dry-run=client -o yaml > configmap.yaml
Copy link
Member

Choose a reason for hiding this comment

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

Not a blocking one and can be tackled in a follow-up if found needed: v1.9.3 is probably CAPZ provider version in this case, might be better to have different name (capz-cm / capz-v1.9.3 as an examples) for cm instead of just version.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 25, 2023
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 695657d88198b3dda42ec6fb1b0377d091761662

@k8s-ci-robot k8s-ci-robot merged commit 006b4ea into kubernetes-sigs:main Jul 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Merge content from ConfigMaps
4 participants