project

package
v4.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 14, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package project provides functionality for managing Ansible-like projects in KubeKey. It handles project file operations, playbook parsing, and task execution.

Index

Constants

View Source
const (
	// PathFormatImportPlaybook defines the directory structure for importing playbooks
	// The structure supports three formats:
	// 1. Import playbook in same directory as base playbook
	// 2. Import playbook from playbooks/ subdirectory
	// 3. Import playbook from project root playbooks/ directory
	PathFormatImportPlaybook = `` /* 165-byte string literal not displayed */

	// PathFormatVarsFile defines the directory structure for vars files
	// Vars files are expected to be in the same directory as the base playbook
	PathFormatVarsFile = `
|-- base-playbook.yaml
|-- [VarsFile]	
`
	// PathFormatRole defines the directory structure for roles
	// Roles can be found in three locations:
	// 1. roles/ directory at project root
	// 2. roles/ directory next to playbook
	// 3. roles/ directory at project root
	PathFormatRole = `` /* 157-byte string literal not displayed */

	// PathFormatRoleMeta defines the directory structure for role meta information.
	// The meta/main.yaml (or main.yml) file can contain dependencies on other roles via the "dependencies" key.
	PathFormatRoleMeta = `
|-- baseRole/
|   |-- meta/
|   |   |-- main.yaml

|-- baseRole/
|   |-- meta/
|   |   |-- main.yml
`

	// PathFormatRoleTask defines the directory structure for role tasks
	// Role tasks are expected to be in tasks/main.yaml or tasks/main.yml under the role directory
	PathFormatRoleTask = `
|-- baseRole/
|   |-- tasks/
|   |   |-- main.yaml

|-- baseRole/
|   |-- tasks/
|   |   |-- main.yml
`

	// PathFormatIncludeTask defines the directory structure for included tasks
	// Tasks can be included from:
	// 1. Direct path under source role
	// 2. tasks/ directory under source role
	// 3. Direct path under top level role
	// 4. tasks/ directory under top level role
	PathFormatIncludeTask = `` /* 218-byte string literal not displayed */

)

Variables

This section is empty.

Functions

func GetImportPlaybookRelPath

func GetImportPlaybookRelPath(basePlaybook string, includePlaybook string) []string

GetImportPlaybookRelPath returns possible relative paths for an imported playbook based on the base playbook location The format follows PathFormatImportPlaybook structure

func GetIncludeTaskRelPath

func GetIncludeTaskRelPath(top string, source string, includeTask string) []string

GetIncludeTaskRelPath returns possible relative paths for included task files The format follows PathFormatIncludeTask structure

func GetProjectPath

func GetProjectPath(basePlaybook string) string

GetProjectPath from basePlaybook. the Project directory structure can be either:

|-- projectFS/ | |-- basePlaybook.yaml

|-- projectFS/ | |-- playbooks/ | | |-- basePlaybook.yaml

func GetRoleDefaultsRelDirPath

func GetRoleDefaultsRelDirPath(baseRole string) []string

GetRoleDefaultsRelDirPath returns possible relative dir paths for a role's defaults files The format follows similar structure to role tasks

func GetRoleDefaultsRelPath

func GetRoleDefaultsRelPath(baseRole string) []string

GetRoleDefaultsRelPath returns possible relative paths for a role's defaults file The format follows similar structure to role tasks

func GetRoleMetaRelPath

func GetRoleMetaRelPath(baseRole string) []string

GetRoleMetaRelPath returns possible relative paths for a role's meta file (main.yaml or main.yml) within the meta directory. The format follows the standard Ansible role meta directory structure.

func GetRoleRelPath

func GetRoleRelPath(basePlaybook string, role string) []string

GetRoleRelPath returns possible relative paths for a role based on the base playbook location The format follows PathFormatRole structure

func GetRoleTaskRelPath

func GetRoleTaskRelPath(baseRole string) []string

GetRoleTaskRelPath returns possible relative paths for a role's main task file The format follows PathFormatRoleTask structure

func GetVarsFilesRelPath

func GetVarsFilesRelPath(basePlaybook string, varsFile string) []string

GetVarsFilesRelPath returns possible relative paths for vars files based on the base playbook location The format follows PathFormatVarsFile structure

Types

type Project

type Project interface {
	// MarshalPlaybook project file to playbook.
	MarshalPlaybook() (*kkprojectv1.Playbook, error)
	// Stat file or dir in project
	Stat(path string) (os.FileInfo, error)
	// WalkDir dir in project
	WalkDir(path string, f fs.WalkDirFunc) error
	// ReadFile file or dir in project
	ReadFile(path string) ([]byte, error)
	// Rel path file or dir in project
	Rel(root string, path string) (string, error)
}

Project represent location of actual project. get project file should base on it

func New

func New(ctx context.Context, playbook kkcorev1.Playbook, update bool) (Project, error)

New creates a new Project instance based on the provided playbook. If project address is git format, it creates a git project. If playbook has BuiltinsProjectAnnotation, it uses builtinProjectFunc. Otherwise, it creates a local project.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL