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

Adding Helm-To-Operator-Codegen-Sdk Documentation #117

Merged
merged 6 commits into from
Mar 1, 2024
Merged

Adding Helm-To-Operator-Codegen-Sdk Documentation #117

merged 6 commits into from
Mar 1, 2024

Conversation

jain-ashish-sam
Copy link
Contributor

The current pr contains the user-guide as well as developer-guide for helm-to-operator-codegen-sdk which is a part of nephio sdk (https://github.com/nephio-project/nephio-sdk)

@nephio-prow nephio-prow bot requested review from efiacor and tliron February 22, 2024 06:45
Copy link

netlify bot commented Feb 22, 2024

Deploy Preview for nephio ready!

Name Link
🔨 Latest commit 3b73db5
🔍 Latest deploy log https://app.netlify.com/sites/nephio/deploys/65e2117cc8599f0008d36743
😎 Deploy Preview https://deploy-preview-117--nephio.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@efiacor
Copy link
Contributor

efiacor commented Feb 22, 2024

/retest

Copy link
Member

@electrocucaracha electrocucaracha left a comment

Choose a reason for hiding this comment

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

Initial review

@@ -16,6 +16,7 @@ for deploying on Kubernetes, legacy helm support will be required for a number o

### Deployment options

* [Using Helm To Operator Codegen Sdk](/docs/guides/user-guides/helm/helm-to-operator-codegen-sdk-user-guide.md)
Copy link
Member

Choose a reason for hiding this comment

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

I think that relative paths can work here

Suggested change
* [Using Helm To Operator Codegen Sdk](/docs/guides/user-guides/helm/helm-to-operator-codegen-sdk-user-guide.md)
* [Using Helm To Operator Codegen Sdk](helm-to-operator-codegen-sdk-user-guide.md)

The [Helm to Operator Codegen SDK](https://github.com/nephio-project/nephio-sdk/tree/main/helm-to-operator-codegen-sdk) offers a streamlined solution for translating existing Helm charts into Kubernetes operators with minimal effort and cost.

## The Flow Diagram
In a nutshell, Firstly, the Helm-Charts are converted to Yamls using the values provided in "values.yaml". Then, each Kubernetes Resource Manifest (KRM) in the YAML is translated into Go code, employing one of two methods.
Copy link
Member

Choose a reason for hiding this comment

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

https://cloud.google.com/blog/topics/developers-practitioners/build-platform-krm-part-2-how-kubernetes-resource-model-works

Suggested change
In a nutshell, Firstly, the Helm-Charts are converted to Yamls using the values provided in "values.yaml". Then, each Kubernetes Resource Manifest (KRM) in the YAML is translated into Go code, employing one of two methods.
In a nutshell, the Helm-Charts are converted to YAML files using the values provided in "values.yaml". Then, each Kubernetes Resource Model (KRM) in the YAML is translated into Go code, employing one of two methods.

1) If the resource is Runtime-Supported, it undergoes a conversion process where the KRM resource is first transformed into a Runtime Object, then into JSON, and finally into Go code.
2) Otherwise, if the resource is not Runtime-Supported, it is converted into an Unstructured Object and then into Go code.

After the conversion process, all the generated Go code is gathered and compiled into a single Go file. This resulting file contains functions that can be readily utilized by Kubernetes operators.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
After the conversion process, all the generated Go code is gathered and compiled into a single Go file. This resulting file contains functions that can be readily utilized by Kubernetes operators.
After the conversion process, all the generated Go code is gathered and compiled into a single Go file. This process results in a file that contains functions which can be readily utilized by Kubernetes operators.

Comment on lines 18 to 19
### Flow-1: Helm to Yaml
Helm to Yaml conversion is achieved by running the command
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
### Flow-1: Helm to Yaml
Helm to Yaml conversion is achieved by running the command
### Flow-1: Helm to YAML
Helm to YAML conversion is achieved by running the following command

-----
### Flow-1: Helm to Yaml
Helm to Yaml conversion is achieved by running the command
`helm template <chart> --namespace <namespace> --output-dir “temp/templated/”` Internally. As of now, It retrieves the values from default "values.yaml"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
`helm template <chart> --namespace <namespace> --output-dir “temp/templated/”` Internally. As of now, It retrieves the values from default "values.yaml"
`helm template <chart> --namespace <namespace> --output-dir “temp/templated/”` Internally. As of now, it retrieves the values from default "values.yaml"

Helm to Yaml conversion is achieved by running the command
`helm template <chart> --namespace <namespace> --output-dir “temp/templated/”` Internally. As of now, It retrieves the values from default "values.yaml"

### Flow-2: Yaml Split
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
### Flow-2: Yaml Split
### Flow-2: YAML Split

`helm template <chart> --namespace <namespace> --output-dir “temp/templated/”` Internally. As of now, It retrieves the values from default "values.yaml"

### Flow-2: Yaml Split
The SDK iterates over each YAML file in the "converted-yamls" directory. If a YAML file contains multiple Kubernetes Resource Manifests (KRM), separated by "---", the SDK splits the YAML file accordingly to isolate each individual KRM resource. This ensures that each KRM resource is processed independently.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
The SDK iterates over each YAML file in the "converted-yamls" directory. If a YAML file contains multiple Kubernetes Resource Manifests (KRM), separated by "---", the SDK splits the YAML file accordingly to isolate each individual KRM resource. This ensures that each KRM resource is processed independently.
The SDK iterates over each YAML file in the "converted-yamls" directory. If a YAML file contains multiple Kubernetes Resource Models (KRMs), separated by "---", the SDK splits the YAML file accordingly to isolate each individual KRM resource. This ensures that each KRM resource is processed independently.

1. GoLang Version: 1.21
2. Helm : v3.9.3
3. Kubebuilder
4. A Kubernetes Cluster with Calico CNI and multus-cni plugin (Can Refer [here](https://medium.com/rahasak/deploying-5g-core-network-with-free5gc-kubernets-and-helm-charts-29741cea3922), Before "Deploy Helm-Chart Part" )
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi when using free5gc I always found it easier to work with Flannel for this reason

ipv4.ip_forward We remind you that some CNI plugins (e.g. Flannel) allow this functionality by default, while others (.e.g. Calico) require a special configuration.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I recall, there were some additional configurations while working with Calico CNI , but thanks for the info about Flannel, I will surely check it out!!

@lapentad
Copy link
Contributor

I think the Check links job is failing because the user guide is not in the _index.md.

Cannot find: helm-to-operator-codegen-sdk-user-guide.md in content/en/docs/guides/user-guides/helm/_index.md


### Flow-3.2: Runtime-Object to JSON
Firstly, the SDK performs a typecast of the runtime object to its actual data type. For instance, if the Kubernetes Kind is "Service," the SDK typecasts the runtime object to the specific data type corev1.Service. Then, it conducts a Depth-First Search (DFS) traversal over the corev1.Service object using reflection. During this traversal, the SDK generates a JSON structure that encapsulates information about the struct hierarchy, including corresponding data types and values. This transformation results in a JSON representation of the corev1.Service object's structure and content.
<details>
Copy link
Contributor

Choose a reason for hiding this comment

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

I would use the <details> tag here, It makes the content collapsed by default, so people will just not recognise it. Is this something what is not important?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am sorry but I didn't understand, you mean to say that you wouldn't use the details tag, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, exactly :)

### Flow-3.3: JSON to String (Go-Code)
The SDK reads the JSON file containing the information about the Kubernetes resource and then translates this information into a string of Go code. This process involves parsing the JSON structure and generating corresponding Go code strings based on the structure, data types, and values extracted from the JSON representation. Ultimately, this results in a string that represents the Kubernetes resource in a format compatible with Go code.

<details>
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should be simply just normal description.

<summary>TraverseJSON Cases (Json-to-String)</summary>


```
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this intro text is added as a code example?


The Config-Jsons are required for more package-specific-types (such as : v1.Service, v1.Deployment)

#### i) Struct_Module_mapping.json
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
#### i) Struct_Module_mapping.json
#### Struct_Module_mapping.json

v1.Service --> corev1.Service
```

#### ii) Enum_Module_mapping.json
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
#### ii) Enum_Module_mapping.json
#### Enum_Module_mapping.json

### Flow-4: KRM to Unstruct-Obj to String(Go-code)
All Kubernetes resource kinds that are not supported by the runtime-object method are handled using the unstructured method. In this approach, the Kubernetes Resource MOdel (KRM) is converted to an unstructured object using the package "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured".
Then, We traverse the unstructured-Obj in a DFS fashion and build the gocode-string.
<details>
Copy link
Contributor

Choose a reason for hiding this comment

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

I would leave the <details>

<summary>DFS Algorithm Cases (Unstruct-Version)</summary>


```
Copy link
Contributor

Choose a reason for hiding this comment

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

All of this is normal description and not example code.

@@ -0,0 +1,333 @@
---
title: Helm to Operator Codegen Sdk Developer Guide
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this a document for the developers of Helm to Operator Codegen Sdk?
If yes, then it should be moved to the Nephio contributor guides section.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it is intended for developers, I will surely move it to "Nephio contributor guides section."

<details>
<summary>The output is similar to:</summary>

```console
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
```console
```bash

<details>
<summary>The output Should be: </summary>

```
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
```
```bash

@jain-ashish-sam
Copy link
Contributor Author

/retest

@jain-ashish-sam
Copy link
Contributor Author

jain-ashish-sam commented Feb 26, 2024

Hi @CsatariGergely , can you help me resolve the "broken-links" issue/ "linkspector job failing".
I have checked the links in my own local hugo server, as well as the netlify-preview (https://deploy-preview-117--nephio.netlify.app/). The links seems to work there just fine. I have tried relative-links in one old-commit, but still the job-failed.
Therefore, I am not able to get "why the job is failing."
The logs of the job don't seem to be much helpful, (https://github.com/nephio-project/docs/actions/runs/8047908663/job/21978126772?pr=117)

Run linkspector check -c .linkspector.yml
  linkspector check -c .linkspector.yml
  shell: /usr/bin/bash -e {0}
💥 Error: Protocol error (Target.closeTarget): Session with given id not found.
Error: Process completed with exit code 1.

@CsatariGergely
Copy link
Contributor

CsatariGergely commented Feb 27, 2024

Hi @CsatariGergely , can you help me resolve the "broken-links" issue/ "linkspector job failing". I have checked the links in my own local hugo server, as well as the netlify-preview (https://deploy-preview-117--nephio.netlify.app/). The links seems to work there just fine. I have tried relative-links in one old-commit, but still the job-failed. Therefore, I am not able to get "why the job is failing." The logs of the job don't seem to be much helpful, (https://github.com/nephio-project/docs/actions/runs/8047908663/job/21978126772?pr=117)

Run linkspector check -c .linkspector.yml
  linkspector check -c .linkspector.yml
  shell: /usr/bin/bash -e {0}
💥 Error: Protocol error (Target.closeTarget): Session with given id not found.
Error: Process completed with exit code 1.

Hi, I think it is "just" a flaky run. Someone with elevated rights could re-run the failed jobs.
I could run it in my machine fork and it gave more meaningful results:
image

This change will fix the error.

@CsatariGergely
Copy link
Contributor

/retest

/retest does not re-run the link check job. Maybe we can add some config to prow bot to do that?

Copy link
Contributor

nephio-prow bot commented Feb 27, 2024

@CsatariGergely: The /retest command does not accept any targets.
The following commands are available to trigger required jobs:

  • /test env-test-sample-prow-job
  • /test presubmit-test-docs-inrepoconfig-validation

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

  • env-test-sample-prow-job

In response to this:

/retest

/retest does not re-run the link check job. Maybe we can add some config to prow bot to do that?

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.

Co-authored-by: Gergely Csatari <[email protected]>
@jain-ashish-sam
Copy link
Contributor Author

So, any more comments anyone?

@jain-ashish-sam
Copy link
Contributor Author

jain-ashish-sam commented Feb 29, 2024

@efiacor @lapentad @CsatariGergely @electrocucaracha @liamfallon @tliron ,If there are not further comments, Can we merge this PR?

-----
### Flow-1: Helm to YAML
Helm to YAML conversion is achieved by running the following command
`helm template <chart> --namespace <namespace> --output-dir “temp/templated/”` Internally. As of now, it retrieves the values from default "values.yaml"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
`helm template <chart> --namespace <namespace> --output-dir “temp/templated/”` Internally. As of now, it retrieves the values from default "values.yaml"
`helm template <chart> --namespace <namespace> --output-dir “temp/templated/”` internally. As of now, it retrieves the values from default "values.yaml"


By utilizing the Helm to Operator Codegen SDK, users can efficiently convert existing Helm charts into Kubernetes operators. This transition enables users to leverage the advanced capabilities provided by Kubernetes operators, such as enhanced automation, lifecycle management, and custom logic handling. Overall, the SDK facilitates a smooth migration process, empowering users to embrace the operator model for managing their Kubernetes resources effectively.

## Excercise: Deploying Free5gc using operator
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
## Excercise: Deploying Free5gc using operator
## Exercise: Deploying Free5gc using operator

@jain-ashish-sam
Copy link
Contributor Author

@efiacor @lapentad @CsatariGergely @electrocucaracha @liamfallon @tliron , any further comments?

@liamfallon
Copy link
Member

/approve

Copy link
Contributor

nephio-prow bot commented Mar 1, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: liamfallon

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

@nephio-prow nephio-prow bot added the approved label Mar 1, 2024
@electrocucaracha
Copy link
Member

/lgtm

@nephio-prow nephio-prow bot added the lgtm label Mar 1, 2024
@nephio-prow nephio-prow bot merged commit 3ff3f62 into nephio-project:main Mar 1, 2024
8 checks passed
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.

6 participants