pkg

package
v0.0.0-...-50752a0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: Apache-2.0 Imports: 33 Imported by: 2

Documentation

Index

Constants

View Source
const (
	DevfileName             = "devfile"
	HiddenDevfileName       = ".devfile"
	YamlExtension           = ".yaml"
	YmlExtension            = ".yml"
	HiddenDevfileDir        = ".devfile"
	DockerfileName          = "Dockerfile"
	AlternateDockerfileName = "dockerfile"
	ContainerfileName       = "Containerfile"
	HiddenDockerDir         = ".docker"
	DockerDir               = "docker"
	BuildDir                = "build"

	Devfile                   = DevfileName + YamlExtension                                // devfile.yaml
	HiddenDevfile             = HiddenDevfileName + YamlExtension                          // .devfile.yaml
	DevfileYml                = DevfileName + YmlExtension                                 // devfile.yml
	HiddenDevfilYml           = HiddenDevfileName + YmlExtension                           // .devfile.yml
	HiddenDirDevfile          = HiddenDevfileDir + "/" + DevfileName + YamlExtension       // .devfile/devfile.yaml
	HiddenDirHiddenDevfile    = HiddenDevfileDir + "/" + HiddenDevfileName + YamlExtension // .devfile/.devfile.yaml
	HiddenDirDevfileYml       = HiddenDevfileDir + "/" + DevfileName + YmlExtension        // .devfile/devfile.yml
	HiddenDirHiddenDevfileYml = HiddenDevfileDir + "/" + HiddenDevfileName + YmlExtension  // .devfile/.devfile.yml

	Dockerfile                   = DockerfileName                                  // Dockerfile
	HiddenDirDockerfile          = HiddenDockerDir + "/" + DockerfileName          // .docker/Dockerfile
	DockerDirDockerfile          = DockerDir + "/" + DockerfileName                // docker/Dockerfile
	BuildDirDockerfile           = BuildDir + "/" + DockerfileName                 // build/Dockerfile
	AlternateDockerfile          = AlternateDockerfileName                         // dockerfile
	HiddenDirAlternateDockerfile = HiddenDockerDir + "/" + AlternateDockerfileName // .docker/dockerfile
	DockerDirAlternateDockerfile = DockerDir + "/" + AlternateDockerfileName       // docker/dockerfile
	BuildDirAlternateDockerfile  = BuildDir + "/" + AlternateDockerfileName        // build/dockerfile

	Containerfile          = ContainerfileName                         // Containerfile
	HiddenDirContainerfile = HiddenDockerDir + "/" + ContainerfileName // .docker/Containerfile
	DockerDirContainerfile = DockerDir + "/" + ContainerfileName       // docker/Containerfile
	BuildDirContainerfile  = BuildDir + "/" + ContainerfileName        // build/Containerfile

	// DevfileRegistryEndpoint is the endpoint of the devfile registry
	DevfileRegistryEndpoint = "https://registry.devfile.io"

	// DevfileStageRegistryEndpoint is the endpoint of the staging devfile registry
	DevfileStageRegistryEndpoint = "https://registry.stage.devfile.io"

	// CDQAnalysisImage is the image of the go module, to spwan the k8s job
	CDQAnalysisImage = "quay.io/redhat-appstudio/cdq-analysis:latest"
)
View Source
const (
	RepoNotFoundMsg         = "repository .* not found"
	RevisionNotFoundMsg     = "pathspec .* did not match any file(s) known to git"
	AuthenticationFailedMsg = "Authentication failed .*"
)
View Source
const (
	HTTPRequestResponseTimeout = 30 * time.Second
)

Variables

Functions

func AnalyzeAndDetectDevfile

func AnalyzeAndDetectDevfile(a Alizer, path, devfileRegistryURL string) ([]byte, string, string, []int, error)

AnalyzeAndDetectDevfile analyzes and attempts to detect a devfile from the devfile registry for a given local path The following values are returned, in addition to an error 1. the detected devfile, in bytes 2. the detected endpoints in the devfile 3. the detected type of the source code 4. the detected ports found in the source code

func AnalyzePath

func AnalyzePath(log logr.Logger, a Alizer, localpath, context, devfileRegistryURL string, devfileMapFromRepo map[string][]byte, devfilesURLMapFromRepo, dockerfileContextMapFromRepo map[string]string, componentPortsMapFromRepo map[string][]int, isDevfilePresent, isDockerfilePresent bool) error

AnalyzePath checks if a devfile or a Dockerfile can be found in the localpath for the given context, this is a helper func used by the CDQ controller In addition to returning an error, the following maps may be updated: devfileMapFromRepo: a context to the devfile bytes if present devfilesURLMapFromRepo: a context to the matched devfileURL from the github repository. If no devfile was present, then a link to a matching devfile in the devfile registry will be used instead. dockerfileContextMapFromRepo: a context to the Dockerfile uri or a matched DockerfileURL from the devfile registry if no Dockerfile is present in the context componentPortsMapFromRepo: a context to the list of ports that were detected by alizer in the source code, at that given context

func CloneAndAnalyze

func CloneAndAnalyze(k K8sInfoClient, namespace, name, context string, cdqInfo *CDQInfo, cdqUtil CDQUtil) (devfilesMap map[string][]byte, devfilesURLMap map[string]string, dockerfileContextMap map[string]string, componentPortsMap map[string][]int, revision string, err error)

CloneAndAnalyze clones and analyzes the Git repo with Alizer if necessary and returns devfilesMap, devfilesURLMap, dockerfileContextMap, componentPortsMap, revision and an error

func CloneRepo

func CloneRepo(clonePath string, gitURL GitURL) error

CloneRepo clones the repoURL to specfied clonePath

func ConvertGitHubURL

func ConvertGitHubURL(URL string, revision string, context string) (string, error)

ConvertGitHubURL converts a git url to its raw format adapted from https://github.com/redhat-developer/odo/blob/e63773cc156ade6174a533535cbaa0c79506ffdb/pkg/catalog/catalog.go#L72

func CreateTempPath

func CreateTempPath(prefix string, appFs afero.Afero) (string, error)

CreateTempPath creates a temp path with the prefix using the Afero FS

func CurlEndpoint

func CurlEndpoint(endpoint, token string) ([]byte, error)

CurlEndpoint curls the endpoint and returns the response or an error if the response is a non-200 status

func FindValidDevfiles

func FindValidDevfiles(cdqInfo *CDQInfo) ([]byte, error)

FindValidDevfiles will search through the list of valid devfile locations and update the DevfileInfo object if a valid devfilepath is found

func FindValidDockerfile

func FindValidDockerfile(cdqInfo *CDQInfo) ([]byte, error)

func GetBranchFromRepo

func GetBranchFromRepo(clonePath string) (string, error)

GetBranchFromRepo gets the current branch from the cloned repository

func GetDevfileAndDockerFilePaths

func GetDevfileAndDockerFilePaths(client CDQInfo) (string, string)

func GetRepoFromRegistry

func GetRepoFromRegistry(name, registryURL string) (string, error)

GetRepoFromRegistry gets the sample repo link from the devfile registry

func IsExist

func IsExist(path string) (bool, error)

IsExist returns whether the given file or directory exists

func IsExisting

func IsExisting(fs afero.Fs, path string) (bool, error)

IsExisting returns bool whether path exists

func NewFilesystem

func NewFilesystem() afero.Afero

NewFilesystem returns a local filesystem based afero FS implementation.

func NewMemoryFilesystem

func NewMemoryFilesystem() afero.Afero

NewMemoryFilesystem returns an in-memory afero FS implementation.

func NewReadOnlyFs

func NewReadOnlyFs() afero.Afero

NewReadOnlyFs returns a read-only file system

func ParseDevfile

func ParseDevfile(src DevfileSrc) (data.DevfileData, error)

ParseDevfile calls the devfile library's parse and returns the devfile data. Provide either a Data src or the URL src Deprecated, use ParseDevfileWithParserArgs instead

func ParseDevfileWithParserArgs

func ParseDevfileWithParserArgs(parserArgs *parser.ParserArgs) (data.DevfileData, error)

ParseDevfileWithParserArgs is an alternative implementation of ParseDevfile which gives the client the flexibility to call the devfile parser with custom parser arguments. The default httpTimeout is set to 10. To override this value, specify the preferred value in parserArgs.HTTPTimeout

func ScanRepo

func ScanRepo(log logr.Logger, a Alizer, localpath string, srcContext string, cdqInfo CDQInfo, cdqUtil CDQUtil) (map[string][]byte, map[string]string, map[string]string, map[string][]int, error)

ScanRepo attempts to read and return devfiles and dockerfiles from the local path upto the specified depth Iterate through each sub-folder under first level, and scan for component. (devfile, dockerfile, then Alizer) If no devfile(s) or dockerfile(s) are found in sub-folders of the root directory, then the Alizer tool is used to detect and match a devfile/dockerfile from the devfile registry ScanRepo returns 3 maps and an error: Map 1 returns a context to the devfile bytes if present. Map 2 returns a context to the matched devfileURL from the devfile registry if no devfile is present in the context. Map 3 returns a context to the Dockerfile uri or a matched DockerfileURL from the devfile registry if no Dockerfile/Containerfile is present in the context Map 4 returns a context to the list of ports that were detected by alizer in the source code, at that given context

func SearchForDockerfile

func SearchForDockerfile(devfileBytes []byte) (*v1alpha2.DockerfileImage, error)

SearchForDockerfile searches for a Dockerfile from a devfile image component. If no Dockerfile is found, nil will be returned. token is required if the devfile has a parent reference to a private repo

func UpdateGitLink(repo, revision, context string) (string, error)

UpdateGitLink updates the relative uri to a full URL link with the context & revision

Types

type Alizer

type Alizer interface {
	SelectDevFileFromTypes(path string, devFileTypes []model.DevfileType) (model.DevfileType, error)
	DetectComponents(path string) ([]model.Component, error)
}

type AlizerClient

type AlizerClient struct {
}

func (AlizerClient) Analyze

func (a AlizerClient) Analyze(path string) ([]model.Language, error)

Analyze is a wrapper call to Alizer's Analyze()

func (AlizerClient) DetectComponents

func (a AlizerClient) DetectComponents(path string) ([]model.Component, error)

func (AlizerClient) SelectDevFileFromTypes

func (a AlizerClient) SelectDevFileFromTypes(path string, devFileTypes []model.DevfileType) (model.DevfileType, error)

SelectDevFileFromTypes is a wrapper call to Alizer's SelectDevFileFromTypes()

type AuthenticationFailed

type AuthenticationFailed struct {
	URL string
	Err error
}

AuthenticationFailed returns an error if authenticated failed when cloning the repository indicates the token is not valid

func (*AuthenticationFailed) Error

func (e *AuthenticationFailed) Error() string

type CDQInfo

type CDQInfo struct {
	DevfileRegistryURL string
	GitURL             GitURL
	ClonedRepo         ClonedInfo
	// contains filtered or unexported fields
}

CDQInfo is a struct that contains the relevant information to 1) clone and search a given git repo for the presence of a devfile or dockerfile and 2) search for matching samples in the devfile registry if no devfile or dockerfiles are found.

type CDQUtil

type CDQUtil interface {
	// Clone is a method signature to help clone a given repository into a path
	Clone(k K8sInfoClient, cdqInfo *CDQInfo, namespace, name, context string) error

	// ValidateDevfile is a method signature to help validate the devfile from the given devfile location
	ValidateDevfile(log logr.Logger, devfileLocation string, token string) (shouldIgnoreDevfile bool, devfileBytes []byte, err error)
}

CDQUtil interface contains all the CDQ utiliy methods that can be implemented by controller and tests

type CDQUtilClient

type CDQUtilClient struct {
}

func NewCDQUtilClient

func NewCDQUtilClient() CDQUtilClient

func (CDQUtilClient) Clone

func (cdqUtilClient CDQUtilClient) Clone(k K8sInfoClient, cdqInfo *CDQInfo, namespace, name, context string) error

func (CDQUtilClient) ValidateDevfile

func (cdqUtilClient CDQUtilClient) ValidateDevfile(log logr.Logger, devfileLocation string, token string) (shouldIgnoreDevfile bool, devfileBytes []byte, err error)

type CDQUtilMockClient

type CDQUtilMockClient struct {
}

func NewCDQUtilMockClient

func NewCDQUtilMockClient() CDQUtilMockClient

func (CDQUtilMockClient) Clone

func (cdqUtilMockClient CDQUtilMockClient) Clone(k K8sInfoClient, cdqInfo *CDQInfo, namespace, name, context string) error

func (CDQUtilMockClient) ValidateDevfile

func (cdqUtilMockClient CDQUtilMockClient) ValidateDevfile(log logr.Logger, devfileLocation string, token string) (shouldIgnoreDevfile bool, devfileBytes []byte, err error)

type ClonedInfo

type ClonedInfo struct {
	ClonedPath    string      // For locally cloned git repos
	ComponentPath string      // For locally cloned git repos
	Fs            afero.Afero // For locally cloned git repos
}

type DevfileSrc

type DevfileSrc struct {
	Data string
	URL  string
	Path string
}

DevfileSrc specifies the src of the Devfile

type GitURL

type GitURL struct {
	RepoURL  string // the repo URL where the devfile is located
	Revision string
	Token    string // TODO: Token should not be exported/exposed via GitURL. CRUD ops should be used to access token
}

type InternalError

type InternalError struct {
	Err error
}

InternalError returns cdq errors other than user error

func (*InternalError) Error

func (e *InternalError) Error() string

type InvalidDevfile

type InvalidDevfile struct {
	Err error
}

InvalidDevfile returns an error if no devfile is invalid

func (*InvalidDevfile) Error

func (e *InvalidDevfile) Error() string

type InvalidURL

type InvalidURL struct {
	URL string
	Err error
}

InvalidURL returns an error if URL is invalid to be parsed

func (*InvalidURL) Error

func (e *InvalidURL) Error() string

type K8sInfoClient

type K8sInfoClient struct {
	Ctx          context.Context
	Clientset    kubernetes.Interface
	Log          logr.Logger
	CreateK8sJob bool
}

func (K8sInfoClient) SendBackDetectionResult

func (k K8sInfoClient) SendBackDetectionResult(devfilesMap map[string][]byte, devfilesURLMap map[string]string, dockerfileContextMap map[string]string, componentPortsMap map[string][]int, revision, name, namespace, clonePath string, Fs afero.Afero, completeError error)

type MockAlizerClient

type MockAlizerClient struct {
}

func (MockAlizerClient) DetectComponents

func (a MockAlizerClient) DetectComponents(path string) ([]model.Component, error)

DetectComponents is a wrapper call to Alizer's DetectComponents()

func (MockAlizerClient) SelectDevFileFromTypes

func (a MockAlizerClient) SelectDevFileFromTypes(path string, devFileTypes []model.DevfileType) (model.DevfileType, error)

SelectDevFileFromTypes is a wrapper call to Alizer's SelectDevFileFromTypes()

type NoDevfileFound

type NoDevfileFound struct {
	Location string
	Err      error
}

NoDevfileFound returns an error if no devfile was found

func (*NoDevfileFound) Error

func (e *NoDevfileFound) Error() string

type NoDockerfileFound

type NoDockerfileFound struct {
	Location string
	Err      error
}

NoDockerfileFound returns an error if no dockerfile was found

func (*NoDockerfileFound) Error

func (e *NoDockerfileFound) Error() string

type RepoNotFound

type RepoNotFound struct {
	URL      string
	Revision string
	Err      error
}

RepoNotFound returns an error if no git repo was found

func (*RepoNotFound) Error

func (e *RepoNotFound) Error() string

Jump to

Keyboard shortcuts

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