// Charts tests support for vendoring helm charts
Charts tests support for vendoring helm charts
// Charts tests support for vendoring helm charts
func (r *AppsSuite) Charts(c *C) {
	dockerClient, err := docker.NewClientFromEnv()
	if err != nil {
		c.Skip("this test requires docker")
	}
	dir := c.MkDir()
	config := docker.BasicConfiguration("127.0.0.1:0", dir)
	registry, err := docker.NewRegistry(config)
	c.Assert(err, IsNil)
	err = registry.Start()
	c.Assert(err, IsNil)
	defer registry.Close()
	imageService, err := docker.NewImageService(docker.RegistryConnectionRequest{
		RegistryAddress: defaults.DockerRegistry,
	})
	c.Assert(err, IsNil)
	vendorer, err := service.NewVendorer(service.VendorerConfig{
		DockerClient: dockerClient,
		ImageService: imageService,
		RegistryURL:  registry.Addr(),
		Packages:     r.Packages,
	})
	c.Assert(err, IsNil)
	apps := r.NewService(c, dockerClient, imageService)
	const manifestBytes = `apiVersion: bundle.gravitational.io/v2
kind: SystemApplication
metadata:
  name: app
  resourceVersion: "0.0.1"`
	const chartManifestBytes = `name: mattermost
version: 2.2.1
description: Mattermost Example
keywords:
  - Demo of Mattermost chart with Gravity
tillerVersion: ">=2.8.0"
`
	const templateBytes = `
apiVersion: v1
kind: Pod
metadata:
  name: webserver
  labels:
    app: sample-application
    role: webserver
spec:
  containers:
  - name: webserver
    image: {{.Values.registry}}alpine:latest
    ports:
      - containerPort: 80
  nodeSelector:
    role: webserver`
	const valuesBytes = `
registry:
`
	resources := []*archive.Item{
		archive.DirItem("resources"),
		archive.DirItem("resources/charts"),
		archive.DirItem("resources/charts/mattermost"),
		archive.DirItem("resources/charts/mattermost/templates"),
		archive.ItemFromString("resources/app.yaml", manifestBytes),
		archive.ItemFromString("resources/charts/mattermost/Chart.yaml", chartManifestBytes),
		archive.ItemFromString("resources/charts/mattermost/values.yaml", valuesBytes),
		archive.ItemFromString("resources/charts/mattermost/templates/pod.yaml", templateBytes),
	}
	application, reader := r.importApplicationWithResources(apps, vendorer, manifestBytes, resources, c)
	defer reader.Close()
	files, err := archive.FetchFiles(reader, []string{"registry"})
	c.Assert(err, IsNil)
	c.Assert(files["resources/charts/mattermost/Chart.yaml"], Equals, chartManifestBytes)
	c.Assert(files["resources/charts/mattermost/values.yaml"], Equals, valuesBytes)
	c.Assert(files["resources/charts/mattermost/templates/pod.yaml"], Equals, templateBytes)
	registryAddr := registryAddr(registry.Addr())
	c.Assert(apps.ExportApp(app.ExportAppRequest{
		Package:         application.Package,
		RegistryAddress: registryAddr,
	}), IsNil)
	ctx := context.Background()
	remoteRegistry, err := docker.ConnectRegistry(
		ctx, docker.RegistryConnectionRequest{
			RegistryAddress: registryAddr,
		})
	c.Assert(err, IsNil)
	repos := make([]string, 2)
	_, err = remoteRegistry.Repositories(ctx, repos, "")
	if err != io.EOF {
		c.Assert(err, IsNil)
	}
	sort.Strings(repos)
	c.Assert(repos, DeepEquals, []string{"alpine", "gravitational/debian-tall"})
}
func ( r * AppsSuite ) Charts ( c * C ) { dockerClient , err := docker . NewClientFromEnv ( ) if err != nil { c . Skip ( " " ) } dir := c . MkDir ( ) config := docker . BasicConfiguration ( " " , dir ) registry , err := docker . NewRegistry ( config ) c . Assert ( err , IsNil ) err = registry . Start ( ) c . Assert ( err , IsNil ) defer registry . Close ( ) imageService , err := docker . NewImageService ( docker . RegistryConnectionRequest { RegistryAddress : defaults . DockerRegistry , } ) c . Assert ( err , IsNil ) vendorer , err := service . NewVendorer ( service . VendorerConfig { DockerClient : dockerClient , ImageService : imageService , RegistryURL : registry . Addr ( ) , Packages : r . Packages , } ) c . Assert ( err , IsNil ) apps := r . NewService ( c , dockerClient , imageService ) const manifestBytes = `apiVersion: bundle.gravitational.io/v2
kind: SystemApplication
metadata:
  name: app
  resourceVersion: "0.0.1"` const chartManifestBytes = `name: mattermost
version: 2.2.1
description: Mattermost Example
keywords:
  - Demo of Mattermost chart with Gravity
tillerVersion: ">=2.8.0"
` const templateBytes = `
apiVersion: v1
kind: Pod
metadata:
  name: webserver
  labels:
    app: sample-application
    role: webserver
spec:
  containers:
  - name: webserver
    image: {{.Values.registry}}alpine:latest
    ports:
      - containerPort: 80
  nodeSelector:
    role: webserver` const valuesBytes = `
registry:
` resources := [ ] * archive . Item { archive . DirItem ( " " ) , archive . DirItem ( " " ) , archive . DirItem ( " " ) , archive . DirItem ( " " ) , archive . ItemFromString ( " " , manifestBytes ) , archive . ItemFromString ( " " , chartManifestBytes ) , archive . ItemFromString ( " " , valuesBytes ) , archive . ItemFromString ( " " , templateBytes ) , } application , reader := r . importApplicationWithResources ( apps , vendorer , manifestBytes , resources , c ) defer reader . Close ( ) files , err := archive . FetchFiles ( reader , [ ] string { " " } ) c . Assert ( err , IsNil ) c . Assert ( files [ " " ] , Equals , chartManifestBytes ) c . Assert ( files [ " " ] , Equals , valuesBytes ) c . Assert ( files [ " " ] , Equals , templateBytes ) registryAddr := registryAddr ( registry . Addr ( ) ) c . Assert ( apps . ExportApp ( app . ExportAppRequest { Package : application . Package , RegistryAddress : registryAddr , } ) , IsNil ) ctx := context . Background ( ) remoteRegistry , err := docker . ConnectRegistry ( ctx , docker . RegistryConnectionRequest { RegistryAddress : registryAddr , } ) c . Assert ( err , IsNil ) repos := make ( [ ] string , 2 ) _ , err = remoteRegistry . Repositories ( ctx , repos , " " ) if err != io . EOF { c . Assert ( err , IsNil ) } sort . Strings ( repos ) c . Assert ( repos , DeepEquals , [ ] string { " " , " " } ) }
Charts tests support for vendoring helm charts
Charts tests support for vendoring helm charts
// import another version and check that resources have been updated // files were not changed // alpine was referenced as a part of helm template, // but make sure helm template has captured it // and added to the list of vendored apps