Skip to content

Proposal to add ApplyInlineYaml and DeleteInlineYaml methods to the C# Kubernetes client #1608

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

Open
josephaw1022 opened this issue Jan 17, 2025 · 3 comments
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.

Comments

@josephaw1022
Copy link

Background

I have experience working with Helm charts, where I frequently read and write YAML files to define Kubernetes resources. Recently, I’ve been working on creating an operator with KubeOps, and in that process, I realized that having a method like ApplyInlineYaml and DeleteInlineYaml in the C# Kubernetes client would make it much easier to follow exactly what is being created and deleted.

While it is not difficult to read C# code and understand how it is converted into YAML, it would be much more intuitive (at least for me) if I could define my resources using inline YAML. This would simplify the process of defining and managing resources directly in the code, reducing the mental overhead of mapping between C# objects and their YAML representations.

Proposal

Adding two new methods to the IKubernetes interface:

ApplyInlineYaml: This method would allow users to apply Kubernetes resources defined as YAML strings directly to a cluster.
DeleteInlineYaml: This method would allow users to delete Kubernetes resources defined as YAML strings directly from a cluster.

Example Usage

// ... omitted dependencies

public class Program
{
    private static async Task Main(string[] args)
    {
        var config = KubernetesClientConfiguration.BuildConfigFromConfigFile();
        IKubernetes client = new Kubernetes(config);

        var inlineResources = """
          # Namespace Definition
          apiVersion: v1
          kind: Namespace
          metadata:
            name: simple-namespace

          ---

          # Deployment Definition
          apiVersion: apps/v1
          kind: Deployment
          metadata:
            name: simple-deployment
            namespace: simple-namespace
          spec:
            replicas: 1
            selector:
              matchLabels:
                app: simple-app
            template:
              metadata:
                labels:
                  app: simple-app
              spec:
                containers:
                - name: simple-container
                  image: nginx:latest
                  ports:
                  - containerPort: 80
        """;

        // To create or update the resources
        client.ApplyInlineYaml(inlineResources);

        // To delete the resources
        client.DeleteInlineYaml(inlineResources);
    }
}

Existing Example:

There is already an example in the official C# Kubernetes client repository (Program.cs) that demonstrates how to load and apply Kubernetes resources from YAML. This approach works, but it is not ideal for operator development, where the simplicity of applying or deleting resources from inline YAML would be more efficient. Simplifying this process into a single method call for each action (apply and delete) would streamline workflows, especially in operator development.

@tg123
Copy link
Member

tg123 commented Jan 17, 2025

thank you
this is planned in kubectl sdk

it will provide same experience as kubectl cli

however, we don't have enough contributors for it
i was a bit busy recently and don't have enough time on it

pr to kubectl project is welcomed

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle stale
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Apr 17, 2025
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle rotten
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels May 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.
Projects
None yet
Development

No branches or pull requests

4 participants