Documentation ¶
Index ¶
- Constants
- Variables
- func AnalyzeAndDetectDevfile(a Alizer, path, devfileRegistryURL string) ([]byte, string, string, []int, error)
- func AnalyzePath(log logr.Logger, a Alizer, localpath, context, devfileRegistryURL string, ...) error
- func CloneAndAnalyze(k K8sInfoClient, namespace, name, context string, cdqInfo *CDQInfo, ...) (devfilesMap map[string][]byte, devfilesURLMap map[string]string, ...)
- func CloneRepo(clonePath string, gitURL GitURL) error
- func ConvertGitHubURL(URL string, revision string, context string) (string, error)
- func CreateTempPath(prefix string, appFs afero.Afero) (string, error)
- func CurlEndpoint(endpoint, token string) ([]byte, error)
- func FindValidDevfiles(cdqInfo *CDQInfo) ([]byte, error)
- func FindValidDockerfile(cdqInfo *CDQInfo) ([]byte, error)
- func GetBranchFromRepo(clonePath string) (string, error)
- func GetDevfileAndDockerFilePaths(client CDQInfo) (string, string)
- func GetRepoFromRegistry(name, registryURL string) (string, error)
- func IsExist(path string) (bool, error)
- func IsExisting(fs afero.Fs, path string) (bool, error)
- func NewFilesystem() afero.Afero
- func NewMemoryFilesystem() afero.Afero
- func NewReadOnlyFs() afero.Afero
- func ParseDevfile(src DevfileSrc) (data.DevfileData, error)
- func ParseDevfileWithParserArgs(parserArgs *parser.ParserArgs) (data.DevfileData, error)
- func ScanRepo(log logr.Logger, a Alizer, localpath string, srcContext string, ...) (map[string][]byte, map[string]string, map[string]string, map[string][]int, ...)
- func SearchForDockerfile(devfileBytes []byte) (*v1alpha2.DockerfileImage, error)
- func UpdateGitLink(repo, revision, context string) (string, error)
- type Alizer
- type AlizerClient
- type AuthenticationFailed
- type CDQInfo
- type CDQUtil
- type CDQUtilClient
- type CDQUtilMockClient
- type ClonedInfo
- type DevfileSrc
- type GitURL
- type InternalError
- type InvalidDevfile
- type InvalidURL
- type K8sInfoClient
- type MockAlizerClient
- type NoDevfileFound
- type NoDockerfileFound
- type RepoNotFound
Constants ¶
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" )
const ( RepoNotFoundMsg = "repository .* not found" RevisionNotFoundMsg = "pathspec .* did not match any file(s) known to git" AuthenticationFailedMsg = "Authentication failed .*" )
const (
HTTPRequestResponseTimeout = 30 * time.Second
)
Variables ¶
var ValidDevfileLocations = []string{Devfile, HiddenDevfile, DevfileYml, HiddenDevfilYml, HiddenDirDevfile, HiddenDirHiddenDevfile, HiddenDirDevfileYml, HiddenDirHiddenDevfileYml}
var ValidDockerfileLocations = []string{Dockerfile, DockerDirDockerfile, HiddenDirDockerfile, BuildDirDockerfile, AlternateDockerfile, DockerDirAlternateDockerfile, HiddenDirAlternateDockerfile, BuildDirAlternateDockerfile, Containerfile, DockerDirContainerfile, HiddenDirContainerfile, BuildDirContainerfile}
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 ConvertGitHubURL ¶
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 ¶
CreateTempPath creates a temp path with the prefix using the Afero FS
func CurlEndpoint ¶
CurlEndpoint curls the endpoint and returns the response or an error if the response is a non-200 status
func FindValidDevfiles ¶
FindValidDevfiles will search through the list of valid devfile locations and update the DevfileInfo object if a valid devfilepath is found
func FindValidDockerfile ¶
func GetBranchFromRepo ¶
GetBranchFromRepo gets the current branch from the cloned repository
func GetRepoFromRegistry ¶
GetRepoFromRegistry gets the sample repo link from the devfile registry
func IsExisting ¶
IsExisting returns bool whether path exists
func NewFilesystem ¶
NewFilesystem returns a local filesystem based afero FS implementation.
func NewMemoryFilesystem ¶
NewMemoryFilesystem returns an in-memory afero FS implementation.
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 ¶
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 ¶
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 ¶
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 ¶
type ClonedInfo ¶
type DevfileSrc ¶
DevfileSrc specifies the src of the Devfile
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 ¶
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 ¶
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 ¶
NoDevfileFound returns an error if no devfile was found
func (*NoDevfileFound) Error ¶
func (e *NoDevfileFound) Error() string
type NoDockerfileFound ¶
NoDockerfileFound returns an error if no dockerfile was found
func (*NoDockerfileFound) Error ¶
func (e *NoDockerfileFound) Error() string
type RepoNotFound ¶
RepoNotFound returns an error if no git repo was found
func (*RepoNotFound) Error ¶
func (e *RepoNotFound) Error() string