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

Apply additional kube manifests from configs to cluster #817

Merged
merged 3 commits into from
Jan 16, 2025
Merged

Conversation

kke
Copy link
Contributor

@kke kke commented Jan 15, 2025

Additional feature for #812

Any encountered configuration files that are in the "kubernetes resource" format (contains apiVersion and kind fields) will be applied to the cluster using kubectl apply as the last step before disconnect during a k0sctl apply action.

Example YAML:

apiVersion: k0sctl.k0sproject.io/v1beta1
kind: cluster
spec:
  hosts:
    - role: single
      ssh:
        address: 10.0.0.1
---
apiVersion: v1
kind: Pod
metadata:
  name: hello
spec:
  containers:
  - name: hello
    image: nginx:alpine
    ports:
    - containerPort: 80

@kke kke added the enhancement New feature or request label Jan 15, 2025
@kke kke changed the base branch from main to multidoc-yamls January 15, 2025 13:17
@kke kke force-pushed the apply-manifests branch from 5f1d8d3 to 75de152 Compare January 15, 2025 13:28
@kke kke force-pushed the multidoc-yamls branch 2 times, most recently from 168eadb to 1d181af Compare January 15, 2025 13:34
@kke kke force-pushed the apply-manifests branch from 75de152 to 058fc19 Compare January 15, 2025 13:34
@kke kke changed the title (split) Apply additional manifests from multiple / multidoc configs to cluster Apply additional kube manifests from loaded configs to cluster Jan 15, 2025
Base automatically changed from multidoc-yamls to main January 16, 2025 07:47
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>

---------

Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
@kke kke force-pushed the apply-manifests branch from 27e7ab4 to c6de086 Compare January 16, 2025 07:52
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
@kke kke marked this pull request as ready for review January 16, 2025 09:32
@kke kke changed the title Apply additional kube manifests from loaded configs to cluster Apply additional kube manifests from configs to cluster Jan 16, 2025
@kke kke requested a review from jnummelin January 16, 2025 10:51
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
Copy link
Member

@jnummelin jnummelin left a comment

Choose a reason for hiding this comment

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

One minor question only, otherwise LGTM

cfg.Metadata.Manifests = make(map[string][]byte)
log.Debugf("found %d additional resources in the configuration", len(otherConfigs))
for _, otherConfig := range otherConfigs {
log.Debugf("found resource: %s (%d bytes)", otherConfig.Filename(), len(otherConfig.Raw))
Copy link
Member

Choose a reason for hiding this comment

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

Aren't we loading all otherConfigs from a single yaml doc? In this case, what does otherConfig.Filename() refer to?

Copy link
Contributor Author

@kke kke Jan 16, 2025

Choose a reason for hiding this comment

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

k0sctl accepts multiple --configs or a dir --config configs/ (which gets converted to configs/**/*.{yml,yaml} or a glob pattern --config "configs/k0s*.yaml", not only a single multidoc yaml.

The manifest reader tries to keep track of their origins for displaying messages, but if it came from stdin or it doesn't know the filename for some other reason, it either just calls it "manifest" (during preliminary reading/unmarshaling) or calls it fmt.Sprintf("%s-%s-%d.yaml", safeFn(rd.APIVersion), safeFn(rd.Kind), time.Now().UnixNano()) (once the header has been parsed).

@kke kke merged commit 22a352b into main Jan 16, 2025
40 checks passed
@kke kke deleted the apply-manifests branch January 16, 2025 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants