Skip to content

Library to generate Kubernetes objects from a devfile and accessing the devfile registry

License

Notifications You must be signed in to change notification settings

devfile/library

Folders and files

NameName
Last commit message
Last commit date
Mar 3, 2021
Mar 12, 2021
Mar 11, 2021
Mar 3, 2021
Jul 23, 2020
Mar 3, 2021
Nov 9, 2020
Mar 3, 2021
Mar 11, 2021
Mar 11, 2021
Mar 11, 2021
Mar 12, 2021
Mar 3, 2021
Mar 3, 2021

Repository files navigation

Devfile Parser Library

About

The Devfile Parser library is a Golang module that:

  1. parses the devfile.yaml as specified by the api & schema.
  2. writes to the devfile.yaml with the updated data.
  3. generates Kubernetes objects for the various devfile resources.
  4. defines util functions for the devfile.

The function documentation can be accessed via pkg.go.dev.

  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{})
    
     // To get all the components from the devfile with attributes tagged - tool: console-import & import: {strategy: Dockerfile}
    components, err := devfile.Data.GetComponents(DevfileOptions{
         Filter: map[string]interface{}{
    			"tool": "console-import",
    			"import": map[string]interface{}{
    				"strategy": "Dockerfile",
    			},
    		},
    })
    
  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)
    



Run updateApi.sh can update to use latest github.com/devfile/api and update the schema saved under pkg/devfile/parser/data

The script also accepts version number as an argument to update devfile schema for a specific devfile version. For example, run the following command will update devfile schema for 2.0.0

./updateApi.sh 2.0.0

Running the script with no arguments will default to update the latest devfile version

Usage

In the future, the following projects will be consuming this library as a Golang dependency

Issues

Issues are tracked in the devfile/api repo with the label area/library

About

Library to generate Kubernetes objects from a devfile and accessing the devfile registry

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages