Skip to content

Commit

Permalink
CLI commands support for packages in airgapped admin (#8865)
Browse files Browse the repository at this point in the history
Co-authored-by: Aravind Ramalingam <ramaliar@amazon.com>
  • Loading branch information
eks-distro-pr-bot and pokearu authored Oct 18, 2024
1 parent 902c6ab commit 94698ca
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 6 deletions.
21 changes: 18 additions & 3 deletions cmd/eksctl-anywhere/cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package cmd
import (
"context"

anywherev1 "github.com/aws/eks-anywhere/pkg/api/v1alpha1"
"github.com/aws/eks-anywhere/pkg/cluster"
"github.com/aws/eks-anywhere/pkg/dependencies"
"github.com/aws/eks-anywhere/pkg/files"
"github.com/aws/eks-anywhere/pkg/helm"
"github.com/aws/eks-anywhere/pkg/kubeconfig"
"github.com/aws/eks-anywhere/pkg/manifests/bundles"
"github.com/aws/eks-anywhere/pkg/registrymirror"
"github.com/aws/eks-anywhere/pkg/version"
"github.com/aws/eks-anywhere/release/api/v1alpha1"
)
Expand Down Expand Up @@ -50,7 +52,7 @@ func getKubeconfigPath(clusterName, override string) string {

func NewDependenciesForPackages(ctx context.Context, opts ...PackageOpt) (*dependencies.Dependencies, error) {
config := New(opts...)
return dependencies.NewFactory().
f := dependencies.NewFactory().
WithExecutableMountDirs(config.mountPaths...).
WithCustomBundles(config.bundlesOverride).
WithExecutableBuilder().
Expand All @@ -59,8 +61,13 @@ func NewDependenciesForPackages(ctx context.Context, opts ...PackageOpt) (*depen
WithHelm(helm.WithInsecure()).
WithCuratedPackagesRegistry(config.registryName, config.kubeVersion, version.Get()).
WithPackageControllerClient(config.spec, config.kubeConfig).
WithLogger().
Build(ctx)
WithLogger()

if config.cluster != nil && config.cluster.Spec.RegistryMirrorConfiguration != nil {
f.WithRegistryMirror(registrymirror.FromCluster(config.cluster))
}

return f.Build(ctx)
}

type PackageOpt func(*PackageConfig)
Expand All @@ -72,6 +79,7 @@ type PackageConfig struct {
mountPaths []string
spec *cluster.Spec
bundlesOverride string
cluster *anywherev1.Cluster
}

func New(options ...PackageOpt) *PackageConfig {
Expand Down Expand Up @@ -118,3 +126,10 @@ func WithBundlesOverride(bundlesOverride string) func(*PackageConfig) {
config.bundlesOverride = bundlesOverride
}
}

// WithCluster sets cluster in the config with incoming value.
func WithCluster(cluster *anywherev1.Cluster) func(config *PackageConfig) {
return func(config *PackageConfig) {
config.cluster = cluster
}
}
21 changes: 20 additions & 1 deletion cmd/eksctl-anywhere/cmd/generatepackage.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import (
"log"

"github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/types"

anywherev1 "github.com/aws/eks-anywhere/pkg/api/v1alpha1"
"github.com/aws/eks-anywhere/pkg/clients/kubernetes"
"github.com/aws/eks-anywhere/pkg/constants"
"github.com/aws/eks-anywhere/pkg/curatedpackages"
"github.com/aws/eks-anywhere/pkg/kubeconfig"
)
Expand Down Expand Up @@ -70,7 +74,22 @@ func generatePackages(ctx context.Context, args []string) error {
return err
}

deps, err := NewDependenciesForPackages(ctx, WithRegistryName(gpOptions.registry), WithKubeVersion(gpOptions.kubeVersion), WithMountPaths(kubeConfig), WithBundlesOverride(gpOptions.bundlesOverride))
k8sClient, err := kubernetes.NewRuntimeClientFromFileName(kubeConfig)
if err != nil {
return fmt.Errorf("unable to initalize k8s client: %v", err)
}

cluster := &anywherev1.Cluster{}
if err := k8sClient.Get(ctx, types.NamespacedName{Name: gpOptions.clusterName, Namespace: constants.DefaultNamespace}, cluster); err != nil {
return fmt.Errorf("unable to get cluster %s: %v", gpOptions.clusterName, err)
}

deps, err := NewDependenciesForPackages(ctx,
WithRegistryName(gpOptions.registry),
WithKubeVersion(gpOptions.kubeVersion),
WithMountPaths(kubeConfig),
WithBundlesOverride(gpOptions.bundlesOverride),
WithCluster(cluster))
if err != nil {
return fmt.Errorf("unable to initialize executables: %v", err)
}
Expand Down
7 changes: 6 additions & 1 deletion cmd/eksctl-anywhere/cmd/installpackagecontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ func installPackageController(ctx context.Context) error {
return fmt.Errorf("the cluster config file provided is invalid: %v", err)
}

deps, err := NewDependenciesForPackages(ctx, WithMountPaths(kubeConfig), WithClusterSpec(clusterSpec), WithKubeConfig(ico.kubeConfig), WithBundlesOverride(ico.bundlesOverride))
deps, err := NewDependenciesForPackages(ctx,
WithMountPaths(kubeConfig),
WithClusterSpec(clusterSpec),
WithKubeConfig(ico.kubeConfig),
WithBundlesOverride(ico.bundlesOverride),
WithCluster(clusterSpec.Cluster))
if err != nil {
return fmt.Errorf("unable to initialize executables: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ require (
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa
golang.org/x/net v0.23.0
golang.org/x/oauth2 v0.15.0
golang.org/x/sys v0.18.0
golang.org/x/text v0.14.0
gopkg.in/ini.v1 v1.67.0
gopkg.in/yaml.v2 v2.4.0
Expand Down Expand Up @@ -187,6 +186,7 @@ require (
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.17.0 // indirect
Expand Down

0 comments on commit 94698ca

Please sign in to comment.