From 83266dfccca97ea33646180de02f03a0e5a3c795 Mon Sep 17 00:00:00 2001 From: Maysun J Faisal Date: Mon, 1 Feb 2021 16:55:40 -0500 Subject: [PATCH] Provide code snippets in ReadMe Signed-off-by: Maysun J Faisal --- README.md | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 29bdf62b..b7804ab2 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,30 @@ The Devfile Parser library is a Golang module that: 4. defines util functions for the devfile. The function documentation can be accessed via [pkg.go.dev](https://pkg.go.dev/github.com/devfile/library). -1. To parse a devfile, visit pkg/devfile/parse.go -2. To get the Kubernetes structs from the devfile, visit pkg/devfile/generator/generators.go +1. To parse a devfile, visit pkg/devfile/parse.go + ``` + // Parses the devfile and validates the devfile data + devfile, err := devfilePkg.ParseAndValidate(devfileLocation) + + // To get all the components from the devfile + components, err := devfile.Data.GetComponents(DevfileOptions{}) + ``` +2. To get the Kubernetes objects from the devfile, visit pkg/devfile/generator/generators.go + ``` + // To get a slice of Kubernetes containers of type corev1.Container from the devfile component containers + containers, err := generator.GetContainers(devfile) + + // To generate a Kubernetes deployment of type v1.Deployment + deployParams := generator.DeploymentParams{ + TypeMeta: generator.GetTypeMeta(deploymentKind, deploymentAPIVersion), + ObjectMeta: generator.GetObjectMeta(name, namespace, labels, annotations), + InitContainers: initContainers, + Containers: containers, + Volumes: volumes, + PodSelectorLabels: labels, + } + deployment := generator.GetDeployment(deployParams) + ``` ## Usage