This repository has been archived by the owner on Oct 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement packages installation APIs for cluster essential
Signed-off-by: Vandana Pathak <[email protected]>
- Loading branch information
Vandana Pathak
committed
Mar 23, 2023
1 parent
e82d452
commit 25ad233
Showing
29 changed files
with
2,051 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright 2023 VMware, Inc. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// Package clusteressentials has APIs for bootstrapping kubernetes cluster | ||
package clusteressentials | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/cppforlife/go-cli-ui/ui" | ||
"k8s.io/client-go/rest" | ||
|
||
"github.com/vmware-tanzu/carvel-imgpkg/pkg/imgpkg/cmd" | ||
"github.com/vmware-tanzu/tanzu-framework/util/carvelhelpers" | ||
"github.com/vmware-tanzu/tanzu-framework/util/kube" | ||
) | ||
|
||
var ( | ||
downloadPackage = downloadClusterEssentialBundle | ||
) | ||
|
||
const tmpDir = "tmp" | ||
|
||
func downloadClusterEssentialBundle(clusterEssentialBundlePath string) error { | ||
var outputBuf, errorBuf bytes.Buffer | ||
writerUI := ui.NewWriterUI(&outputBuf, &errorBuf, nil) | ||
pullOptions := cmd.NewPullOptions(writerUI) | ||
pullOptions.OutputPath = tmpDir | ||
pullOptions.ImageFlags = cmd.ImageFlags{Image: clusterEssentialBundlePath} | ||
return pullOptions.Run() | ||
} | ||
|
||
func InitClusterEssentials(restConfig *rest.Config, clusterEssentialBundlePath string) error { | ||
err := downloadPackage(clusterEssentialBundlePath) | ||
if err != nil { | ||
return fmt.Errorf("unable to download cluster essential manifest: %w", err) | ||
} | ||
|
||
packages, _ := os.ReadDir(tmpDir) | ||
for _, item := range packages { | ||
packageDir := filepath.Join(tmpDir, item.Name()) | ||
generatedManifestBytes, err := carvelhelpers.CarvelPackageProcessor(packageDir) | ||
if err != nil { | ||
return fmt.Errorf("unable to process carvel package: %w", err) | ||
} | ||
err = kube.AppplyResourcesFromManifest(generatedManifestBytes, restConfig) | ||
if err != nil { | ||
return fmt.Errorf("unable to install %s : %w", item.Name(), err) | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright 2023 VMware, Inc. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package clusteressentials | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"k8s.io/client-go/rest" | ||
) | ||
|
||
func Test_InitClusterEssentials(t *testing.T) { | ||
t.Run("fails when unable to download cluster essential bundle ", func(t *testing.T) { | ||
downloadClusterEssentialBundleMock := func(clusterEssentialBundlePath string) error { | ||
return fmt.Errorf("image not found") | ||
} | ||
|
||
downloadPackage = downloadClusterEssentialBundleMock | ||
bundlePath := "some/image" | ||
var restConfig *rest.Config | ||
err := InitClusterEssentials(restConfig, bundlePath) | ||
require.Error(t, err) | ||
require.ErrorContains(t, err, "unable to download cluster essential manifest") | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
module github.com/vmware-tanzu/tanzu-framework/cluster-essentials | ||
|
||
go 1.18 | ||
|
||
replace ( | ||
github.com/vmware-tanzu/tanzu-framework/util => ../util | ||
sigs.k8s.io/cluster-api => sigs.k8s.io/cluster-api v1.2.8 | ||
) | ||
|
||
require ( | ||
github.com/cppforlife/go-cli-ui v0.0.0-20220622150351-995494831c6c | ||
github.com/stretchr/testify v1.8.1 | ||
github.com/vmware-tanzu/carvel-imgpkg v0.36.0 | ||
github.com/vmware-tanzu/tanzu-framework/util v0.0.0-00010101000000-000000000000 | ||
k8s.io/client-go v0.26.3 | ||
) | ||
|
||
require ( | ||
cloud.google.com/go v0.99.0 // indirect | ||
github.com/Azure/azure-sdk-for-go v55.0.0+incompatible // indirect | ||
github.com/Azure/go-autorest v14.2.0+incompatible // indirect | ||
github.com/Azure/go-autorest/autorest v0.11.18 // indirect | ||
github.com/Azure/go-autorest/autorest/adal v0.9.13 // indirect | ||
github.com/Azure/go-autorest/autorest/azure/auth v0.5.2 // indirect | ||
github.com/Azure/go-autorest/autorest/azure/cli v0.4.1 // indirect | ||
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect | ||
github.com/Azure/go-autorest/logger v0.2.1 // indirect | ||
github.com/Azure/go-autorest/tracing v0.6.0 // indirect | ||
github.com/BurntSushi/toml v1.0.0 // indirect | ||
github.com/VividCortex/ewma v1.1.1 // indirect | ||
github.com/aws/aws-sdk-go-v2 v1.7.1 // indirect | ||
github.com/aws/aws-sdk-go-v2/config v1.5.0 // indirect | ||
github.com/aws/aws-sdk-go-v2/credentials v1.3.1 // indirect | ||
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.3.0 // indirect | ||
github.com/aws/aws-sdk-go-v2/internal/ini v1.1.1 // indirect | ||
github.com/aws/aws-sdk-go-v2/service/ecr v1.4.1 // indirect | ||
github.com/aws/aws-sdk-go-v2/service/ecrpublic v1.4.1 // indirect | ||
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.2.1 // indirect | ||
github.com/aws/aws-sdk-go-v2/service/sso v1.3.1 // indirect | ||
github.com/aws/aws-sdk-go-v2/service/sts v1.6.0 // indirect | ||
github.com/aws/smithy-go v1.6.0 // indirect | ||
github.com/awslabs/amazon-ecr-credential-helper/ecr-login v0.0.0-20220517224237-e6f29200ae04 // indirect | ||
github.com/cheggaaa/pb/v3 v3.1.0 // indirect | ||
github.com/chrismellard/docker-credential-acr-env v0.0.0-20220327082430-c57b701bfc08 // indirect | ||
github.com/containerd/stargz-snapshotter/estargz v0.12.1 // indirect | ||
github.com/cppforlife/cobrautil v0.0.0-20221021151949-d60711905d65 // indirect | ||
github.com/cppforlife/color v1.9.1-0.20200716202919-6706ac40b835 // indirect | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/dimchansky/utfbom v1.1.0 // indirect | ||
github.com/docker/cli v20.10.20+incompatible // indirect | ||
github.com/docker/distribution v2.8.1+incompatible // indirect | ||
github.com/docker/docker v20.10.20+incompatible // indirect | ||
github.com/docker/docker-credential-helpers v0.7.0 // indirect | ||
github.com/emicklei/go-restful/v3 v3.9.0 // indirect | ||
github.com/fatih/color v1.13.0 // indirect | ||
github.com/form3tech-oss/jwt-go v3.2.3+incompatible // indirect | ||
github.com/go-logr/logr v1.2.3 // indirect | ||
github.com/go-openapi/jsonpointer v0.19.5 // indirect | ||
github.com/go-openapi/jsonreference v0.20.0 // indirect | ||
github.com/go-openapi/swag v0.19.14 // indirect | ||
github.com/gogo/protobuf v1.3.2 // indirect | ||
github.com/golang/protobuf v1.5.2 // indirect | ||
github.com/google/gnostic v0.5.7-v3refs // indirect | ||
github.com/google/go-cmp v0.5.9 // indirect | ||
github.com/google/go-containerregistry v0.13.0 // indirect | ||
github.com/google/gofuzz v1.2.0 // indirect | ||
github.com/hashicorp/go-version v1.4.0 // indirect | ||
github.com/inconshreveable/mousetrap v1.0.1 // indirect | ||
github.com/jmespath/go-jmespath v0.4.0 // indirect | ||
github.com/josharian/intern v1.0.0 // indirect | ||
github.com/json-iterator/go v1.1.12 // indirect | ||
github.com/k14s/kbld v0.32.0 // indirect | ||
github.com/k14s/semver/v4 v4.0.1-0.20210701191048-266d47ac6115 // indirect | ||
github.com/k14s/starlark-go v0.0.0-20200720175618-3a5c849cc368 // indirect | ||
github.com/klauspost/compress v1.15.11 // indirect | ||
github.com/mailru/easyjson v0.7.6 // indirect | ||
github.com/mattn/go-colorable v0.1.12 // indirect | ||
github.com/mattn/go-isatty v0.0.17 // indirect | ||
github.com/mattn/go-runewidth v0.0.12 // indirect | ||
github.com/mitchellh/go-homedir v1.1.0 // indirect | ||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | ||
github.com/modern-go/reflect2 v1.0.2 // indirect | ||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect | ||
github.com/opencontainers/go-digest v1.0.0 // indirect | ||
github.com/opencontainers/image-spec v1.1.0-rc2 // indirect | ||
github.com/pkg/errors v0.9.1 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
github.com/rivo/uniseg v0.2.0 // indirect | ||
github.com/sirupsen/logrus v1.9.0 // indirect | ||
github.com/spf13/cobra v1.6.1 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
github.com/vbatts/tar-split v0.11.2 // indirect | ||
github.com/vito/go-interact v1.0.1 // indirect | ||
github.com/vmware-tanzu/carvel-vendir v0.24.0 // indirect | ||
github.com/vmware-tanzu/carvel-ytt v0.40.0 // indirect | ||
golang.org/x/crypto v0.3.0 // indirect | ||
golang.org/x/net v0.8.0 // indirect | ||
golang.org/x/oauth2 v0.3.0 // indirect | ||
golang.org/x/sync v0.1.0 // indirect | ||
golang.org/x/sys v0.6.0 // indirect | ||
golang.org/x/term v0.6.0 // indirect | ||
golang.org/x/text v0.8.0 // indirect | ||
golang.org/x/time v0.3.0 // indirect | ||
google.golang.org/appengine v1.6.7 // indirect | ||
google.golang.org/protobuf v1.28.1 // indirect | ||
gopkg.in/inf.v0 v0.9.1 // indirect | ||
gopkg.in/yaml.v2 v2.4.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
k8s.io/api v0.26.3 // indirect | ||
k8s.io/apimachinery v0.26.3 // indirect | ||
k8s.io/klog/v2 v2.80.1 // indirect | ||
k8s.io/kube-openapi v0.0.0-20221207184640-f3cff1453715 // indirect | ||
k8s.io/utils v0.0.0-20221107191617-1a15be271d1d // indirect | ||
sigs.k8s.io/controller-runtime v0.12.3 // indirect | ||
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect | ||
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect | ||
sigs.k8s.io/yaml v1.3.0 // indirect | ||
) |
Oops, something went wrong.