service

package
v0.0.0-...-3bfe646 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2023 License: Apache-2.0 Imports: 50 Imported by: 3

Documentation

Overview

Copyright 2021 Gravitational, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsMetadataPackage

func IsMetadataPackage(envelope pack.PackageEnvelope) bool

IsMetadataPackage determines if the specified package is a metadata package. A metadata package describes a remote package and deserves special handling in certain cases.

func NewVendorer

func NewVendorer(config VendorerConfig) (*vendorer, error)

NewVendorer creates a new vendorer instance.

func PostProcessManifest

func PostProcessManifest(manifest *schema.Manifest)

PostProcessManifest runs post-processing tasks on a validated manifest Note: exported only for the testing code TODO: find a way to unexport this

func PullApp

func PullApp(req AppPullRequest) (*app.Application, error)

PullApp pulls the application specified with app, along with all its dependencies and base application, from the "source" application service and replicates it in the "destination" application service

func PullAppDeps

func PullAppDeps(req AppPullRequest, manifest schema.Manifest) error

PullAppDeps downloads only dependencies for an application described by the provided manifest

func PullPackage

func PullPackage(req PackagePullRequest) (*pack.PackageEnvelope, error)

PullPackage pulls a package from the "source" package service and creates it in the "destination" service

func SyncApp

func SyncApp(ctx context.Context, req SyncRequest) error

SyncApp syncs an application and all its dependencies with registry

Types

type AppPullRequest

type AppPullRequest struct {
	// FieldLogger is used for logging
	logrus.FieldLogger
	// SrcPack is the package service to pull app from
	SrcPack pack.PackageService
	// DstPack is the package service to push app into
	DstPack pack.PackageService
	// SrcApp is the app service to pull app from
	SrcApp app.Applications
	// DstApp is the app service to push app into
	DstApp app.Applications
	// Package is the application package to pull
	Package loc.Locator
	// Labels is the labels to assign to the pulled app
	Labels map[string]string
	// Progress is optional progress reporter
	Progress pack.ProgressReporter
	// Upsert is whether to create or upsert the application
	Upsert bool
	// MetadataOnly allows to pull only app metadata without body
	MetadataOnly bool
	// Parallel defines the number of tasks to run in parallel.
	// If < 0, the number of tasks is unrestricted.
	// If in [0,1], the tasks are executed sequentially.
	Parallel int
}

AppPullRequest describes a request to pull an app with all its dependencies from one app service into another

func (*AppPullRequest) CheckAndSetDefaults

func (r *AppPullRequest) CheckAndSetDefaults() error

CheckAndSetDefaults checks the app pull request and sets some defaults

func (*AppPullRequest) Clone

func (r *AppPullRequest) Clone(locator loc.Locator) AppPullRequest

Clone returns a copy of this request replacing package with the provided one

type Applications

type Applications struct {
	// contains filtered or unexported fields
}

func New

func New(conf Config) (*Applications, error)

New creates a new instance of the application manager

func (*Applications) CreateApp

func (r *Applications) CreateApp(locator loc.Locator, reader io.Reader, labels map[string]string) (*appservice.Application, error)

CreateApp creates a new application from the specified package bytes (reader) and an optional set of package labels using locator as destination for the resulting package

func (*Applications) CreateAppWithManifest

func (r *Applications) CreateAppWithManifest(locator loc.Locator, manifest []byte, reader io.Reader, labels map[string]string) (*appservice.Application, error)

CreateAppWithManifest new application from the specified package bytes (reader) and an optional set of package labels using locator as destination for the resulting package, with supplied manifest

func (*Applications) CreateImportOperation

func (r *Applications) CreateImportOperation(req *appservice.ImportRequest) (*storage.AppOperation, error)

CreateImportOperation initiates import for an application specified with req. Returns the import operation to keep track of the import progress.

func (*Applications) DeleteApp

func (r *Applications) DeleteApp(req appservice.DeleteRequest) error

DeleteApp deletes an application record and the underlying package

func (*Applications) DeleteAppHookJob

func (r *Applications) DeleteAppHookJob(ctx context.Context, req appservice.DeleteAppHookJobRequest) error

DeleteAppHookJob deletes app hook job

func (*Applications) ExportApp

func (r *Applications) ExportApp(req appservice.ExportAppRequest) error

ExportApp exports containers of the specified application and its dependencies into the specified docker registry

func (*Applications) FetchChart

func (r *Applications) FetchChart(locator loc.Locator) (io.ReadCloser, error)

FetchChart returns Helm chart package with the specified application.

func (*Applications) FetchIndexFile

func (r *Applications) FetchIndexFile() (io.Reader, error)

FetchIndexFile returns Helm chart repository index file data.

func (*Applications) GetApp

func (r *Applications) GetApp(locator loc.Locator) (*appservice.Application, error)

GetApp retrieves an application specified with locator

func (*Applications) GetAppInstaller

func (r *Applications) GetAppInstaller(req appservice.InstallerRequest) (installer io.ReadCloser, err error)

GetAppInstaller builds an installer package for the specified application and returns a reader for the contents.

Steps to generate an installer:

  • copy the gravity binary as ./gravity
  • start new backend as ./gravity.db to persist package metadata
  • start new package service in ./packages
  • import {web-assets,gravity,dns,teleport,planet-master,planet-node,application} packages from application package service into local package service running in ./packages

func (*Applications) GetAppManifest

func (r *Applications) GetAppManifest(locator loc.Locator) (io.ReadCloser, error)

GetAppManifest returns a reader to the application manifest

func (*Applications) GetAppResources

func (r *Applications) GetAppResources(locator loc.Locator) (io.ReadCloser, error)

GetAppResources retrieves an application resources specified with locator

func (*Applications) GetImportedApplication

func (r *Applications) GetImportedApplication(op storage.AppOperation) (*appservice.Application, error)

GetImportedApplication returns the imported application identified by the specified import operation

func (*Applications) GetOperationCrashReport

func (r *Applications) GetOperationCrashReport(op storage.AppOperation) (io.ReadCloser, error)

GetOperationCrashReport returns crash report of the specified operation

func (*Applications) GetOperationLogs

func (r *Applications) GetOperationLogs(op storage.AppOperation) (io.ReadCloser, error)

GetOperationLogs returns the reader to the logs of the specified operation

func (*Applications) GetOperationProgress

func (r *Applications) GetOperationProgress(op storage.AppOperation) (*appservice.ProgressEntry, error)

GetOperationProgress returns the last progress record for the specified operation

func (*Applications) ListApps

func (r *Applications) ListApps(req appservice.ListAppsRequest) (apps []appservice.Application, err error)

ListApps lists currently installed applications from the specified repository of the given type

func (*Applications) StartAppHook

StartAppHook starts app hook in async mode

func (*Applications) StatusApp

func (r *Applications) StatusApp(locator loc.Locator) (*appservice.Status, error)

StatusApp retrieves the status of a running application

func (*Applications) StreamAppHookLogs

func (r *Applications) StreamAppHookLogs(ctx context.Context, ref appservice.HookRef, out io.Writer) error

StreamAppHookLogs streams app hook logs to output writer, this is a blocking call

func (*Applications) UninstallApp

func (r *Applications) UninstallApp(locator loc.Locator) (*appservice.Application, error)

UninstallApp uninstalls the specified application from the runtime, with all its dependencies

func (*Applications) UpsertApp

func (r *Applications) UpsertApp(locator loc.Locator, reader io.Reader, labels map[string]string) (*appservice.Application, error)

func (*Applications) WaitAppHook

func (r *Applications) WaitAppHook(ctx context.Context, ref appservice.HookRef) error

WaitAppHook waits for app hook to complete or fail

type Config

type Config struct {
	// Backend defines the backend used for persistency
	Backend storage.Backend
	// Packages defines the package service to use to query / create application
	// package
	Packages pack.PackageService
	// DockerClient defines the interface to the docker.
	// The client is used to manage container images obtained from the application
	// manifest.  It is used to check image presence, pull images from a remote
	// registry and start temporary registry container.
	DockerClient docker.Interface
	// ImageService defines the interface to the private docker registry running inside
	// the cluster.
	// It is used to sync local container images during installation
	// and to push images to another instance during application export.
	ImageService docker.ImageService
	// StateDir defines the directory used to keep intermediate state.
	// This is the location for log files, for instance.
	StateDir string
	// Devmode sets/removes some insecure flags acceptable for development
	Devmode bool
	// Users provides access to user management interface
	Users users.Users
	// CacheResources sets precomputed cache for resources
	CacheResources bool
	// UnpackedDir is the dir where packages are unpacked
	UnpackedDir string
	// ExcludeDeps defines a list of dependencies that will be excluded for the app image
	ExcludeDeps []loc.Locator
	// GetClient constructs kubernetes clients.
	// Either this or Client must be set to use the kubernetes API.
	GetClient func() (*kubernetes.Clientset, error)
	// Client is an optional kubernetes client
	Client *kubernetes.Clientset
	// FieldLogger specifies the optional logger
	log.FieldLogger
	// Charts provides chart repository methods.
	Charts helm.Repository
}

Config defines the set of configuration attributes for an application interface

type PackagePullRequest

type PackagePullRequest struct {
	// FieldLogger is used for logging
	logrus.FieldLogger
	// SrcPack is the package service to pull package from
	SrcPack pack.PackageService
	// DstPack is the package service to push package into
	DstPack pack.PackageService
	// Package is the package to pull
	Package loc.Locator
	// Labels is the labels to assign to the pulled package
	Labels map[string]string
	// Progress is optional progress reporter
	Progress pack.ProgressReporter
	// Upsert is whether to create or upsert the pulled package
	Upsert bool
	// MetadataOnly allows to pull only package metadata without body
	MetadataOnly bool
}

PackagePullRequest describes a request to pull a package from one package service to another

func (*PackagePullRequest) CheckAndSetDefaults

func (r *PackagePullRequest) CheckAndSetDefaults() error

CheckAndSetDefaults checks the package pull request and sets some defaults

type SyncRequest

type SyncRequest struct {
	PackService  pack.PackageService
	AppService   app.Applications
	ImageService docker.ImageService
	Package      loc.Locator
	Progress     utils.Printer
	ScanConfig   *docker.ScanConfig
}

SyncRequest describes a request to sync an application with registry

func (*SyncRequest) CheckAndSetDefaults

func (r *SyncRequest) CheckAndSetDefaults() error

CheckAndSetDefaults validates the request and sets some defaults.

type TestServices

type TestServices struct {
	Backend  storage.Backend
	Packages pack.PackageService
	Apps     *Applications
}

TestServices groups services relevant in package/application tests

func NewTestServices

func NewTestServices(dir string, c *check.C) TestServices

NewTestServices creates a new set of test services

type VendorRequest

type VendorRequest struct {
	// Repository is the name of app repository
	Repository string
	// PackageName is the app name
	PackageName string
	// PackageVersion is the app version
	PackageVersion string
	// ManifestPath is the path to app manifest
	ManifestPath string
	// ResourcePatterns is a list of file path patterns to search for container images
	ResourcePatterns []string
	// IgnoreResourcePatterns is a list of file path patterns to ignore when searching for images
	IgnoreResourcePatterns []string
	// ImageCacheDir is the directory were the pulled docker images are cached between builds
	ImageCacheDir string
	// SetImages is a list of images to rewrite to new versions
	SetImages []loc.DockerImage
	// SetDeps is a list of app dependencies to rewrite to new versions
	SetDeps []loc.Locator
	// VendorRuntime specifies whether to translate runtime images into packages.
	// The vendoring of the runtime package is a multi-step process which also requires
	// access to the package store used for building the final application installer
	// tarball.
	// During the vendoring of individual package tarballs, it is not feasible to also translate
	// the runtime docker image into a telekube package - hence this is initially false.
	VendorRuntime bool
	// Parallel defines the number of tasks to run in parallel.
	// If < 0, the number of tasks is unrestricted.
	// If in [0,1], the tasks are executed sequentially.
	Parallel int
	// ProgressReporter is a special writer, if set, vendorer will output user-friendly
	// information during vendoring
	ProgressReporter utils.Progress
	// Helm contains parameters for rendering Helm charts.
	Helm helm.RenderParameters
	// Pull allows to force-pull Docker images even if they're already present.
	Pull bool
}

VendorRequest combined various vendoring options

type Vendorer

type Vendorer interface {
	// VendorDir takes information from an app vendor request, imports missing docker images if necessary,
	// rewrites image names in the app's resources and returns a path to the directory containing ready
	// to be imported app.
	VendorDir(ctx context.Context, dir string, req VendorRequest) error
	// VendorTarball is the same as VendorDir but accepts a tarball stream and unpacks it before vendoring
	VendorTarball(ctx context.Context, tarball io.ReadCloser, req VendorRequest) (string, error)
}

Vendorer is an interface for interacting with the vendoring helper.

type VendorerConfig

type VendorerConfig struct {
	// DockerClient is the docker client to use to manage images
	DockerClient docker.Interface
	// ImageService is the docker registry service
	docker.ImageService
	// RegistryURL is the URL of the active docker registry to use
	RegistryURL string
	// Packages is the pack service
	Packages pack.PackageService
}

VendorerConfig is configuration for vendorer

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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