github.com/Racer159/jackal@v0.32.7-0.20240401174413-0bd2339e4f2e/src/pkg/packager/sources/cluster.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // SPDX-FileCopyrightText: 2021-Present The Jackal Authors 3 4 // Package sources contains core implementations of the PackageSource interface. 5 package sources 6 7 import ( 8 "fmt" 9 10 "github.com/Racer159/jackal/src/internal/packager/validate" 11 "github.com/Racer159/jackal/src/pkg/cluster" 12 "github.com/Racer159/jackal/src/pkg/layout" 13 "github.com/Racer159/jackal/src/pkg/packager/filters" 14 "github.com/Racer159/jackal/src/pkg/utils" 15 "github.com/Racer159/jackal/src/types" 16 "github.com/defenseunicorns/pkg/helpers" 17 ) 18 19 var ( 20 // verify that ClusterSource implements PackageSource 21 _ PackageSource = (*ClusterSource)(nil) 22 ) 23 24 // NewClusterSource creates a new cluster source. 25 func NewClusterSource(pkgOpts *types.JackalPackageOptions) (PackageSource, error) { 26 if !validate.IsLowercaseNumberHyphenNoStartHyphen(pkgOpts.PackageSource) { 27 return nil, fmt.Errorf("invalid package name %q", pkgOpts.PackageSource) 28 } 29 cluster, err := cluster.NewClusterWithWait(cluster.DefaultTimeout) 30 if err != nil { 31 return nil, err 32 } 33 return &ClusterSource{pkgOpts, cluster}, nil 34 } 35 36 // ClusterSource is a package source for clusters. 37 type ClusterSource struct { 38 *types.JackalPackageOptions 39 *cluster.Cluster 40 } 41 42 // LoadPackage loads a package from a cluster. 43 // 44 // This is not implemented. 45 func (s *ClusterSource) LoadPackage(_ *layout.PackagePaths, _ filters.ComponentFilterStrategy, _ bool) (types.JackalPackage, []string, error) { 46 return types.JackalPackage{}, nil, fmt.Errorf("not implemented") 47 } 48 49 // Collect collects a package from a cluster. 50 // 51 // This is not implemented. 52 func (s *ClusterSource) Collect(_ string) (string, error) { 53 return "", fmt.Errorf("not implemented") 54 } 55 56 // LoadPackageMetadata loads package metadata from a cluster. 57 func (s *ClusterSource) LoadPackageMetadata(dst *layout.PackagePaths, _ bool, _ bool) (types.JackalPackage, []string, error) { 58 dpkg, err := s.GetDeployedPackage(s.PackageSource) 59 if err != nil { 60 return types.JackalPackage{}, nil, err 61 } 62 63 if err := utils.WriteYaml(dst.JackalYAML, dpkg.Data, helpers.ReadUser); err != nil { 64 return types.JackalPackage{}, nil, err 65 } 66 67 return dpkg.Data, nil, nil 68 }