• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

devfile/library: Library to generate Kubernetes objects from a devfile and acces ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

devfile/library

开源软件地址(OpenSource Url):

https://github.com/devfile/library

开源编程语言(OpenSource Language):

Go 99.6%

开源软件介绍(OpenSource Introduction):

Devfile Library

Apache2.0 License

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.

Usage

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

  1. To parse a devfile, visit parse.go source file

    // ParserArgs is the struct to pass into parser functions which contains required info for parsing devfile.
    parserArgs := parser.ParserArgs{
     	Path:              path,
     	FlattenedDevfile:  &flattenedDevfile,
     	RegistryURLs:      registryURLs,
     	DefaultNamespace:  defaultNamespace,
     	Context:           context,
     	K8sClient:         client,
     }
    
    // Parses the devfile and validates the devfile data
    // if top-level variables are not substituted successfully, the warnings can be logged by parsing variableWarning
    devfile, variableWarning, err := devfilePkg.ParseDevfileAndValidate(parserArgs)
  2. To get specific content from devfile

    // 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",
     		},
     	},
    })
    
    // To get all the volume components
    components, err := devfile.Data.GetComponents(DevfileOptions{
     	ComponentOptions: ComponentOptions{
     		ComponentType: v1.VolumeComponentType,
     	},
    })
    
    // To get all the exec commands that belong to the build group
    commands, err := devfile.Data.GetCommands(DevfileOptions{
     	CommandOptions: CommandOptions{
     		CommandType: v1.ExecCommandType,
     		CommandGroupKind: v1.BuildCommandGroupKind,
     	},
    })
  3. To get the Kubernetes objects from the devfile, visit generators.go source file

     // 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)
  4. To update devfile content

    // To update an existing component in devfile object
    err := devfile.Data.UpdateComponent(v1.Component{
    	    Name: "component1",
    	    ComponentUnion: v1.ComponentUnion{
    	    	Container: &v1.ContainerComponent{
    	    		Container: v1.Container{
    	    			Image: "image1",
                 },
             },
         },
    })
    
    // To add a new component to devfile object
    err := devfile.Data.AddComponents([]v1.Component{
         {
            Name: "component2",
            ComponentUnion: v1.ComponentUnion{
                Container: &v1.ContainerComponent{
                    Container: v1.Container{
                        Image: "image2",
                    },
                },
            },
         },
    })
    
    // To delete a component from the devfile object
    err := devfile.Data.DeleteComponent(componentName)
  5. To write to a devfile, visit writer.go source file

    // If the devfile object has been created with devfile path already set, can simply call WriteYamlDevfile to writes the devfile
    err := devfile.WriteYamlDevfile()
    
    
    // To write to a devfile from scratch
    // create a new DevfileData with a specific devfile version
    devfileData, err := data.NewDevfileData(devfileVersion)
    
    // set schema version
    devfileData.SetSchemaVersion(devfileVersion)
    
    // add devfile content use library APIs
    devfileData.AddComponents([]v1.Component{...})
    devfileData.AddCommands([]v1.Commands{...})
    ......
    
    // create a new DevfileCtx
    ctx := devfileCtx.NewDevfileCtx(devfilePath)
    err = ctx.SetAbsPath()
    
    // create devfile object with the new DevfileCtx and DevfileData
    devfile := parser.DevfileObj{
     	Ctx:  ctx,
     	Data: devfileData,
    }
     
    // write to the devfile on disk
    err = devfile.WriteYamlDevfile()

Projects using devfile/library

The following projects are consuming this library as a Golang dependency

Tests

To run unit tests and api tests. Visit library tests to find out more information on tests

make test

Issues

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

Releases

For devfile/library releases, please check the release page.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap