diff --git a/api/v1alpha1/clusterextension_types.go b/api/v1alpha1/clusterextension_types.go index 2e00e7485..ea5aa199a 100644 --- a/api/v1alpha1/clusterextension_types.go +++ b/api/v1alpha1/clusterextension_types.go @@ -83,6 +83,7 @@ const ( TypeInstalled = "Installed" TypeResolved = "Resolved" TypeHasValidBundle = "HasValidBundle" + // TypeDeprecated is a rollup condition that is present when // any of the deprecated conditions are present. TypeDeprecated = "Deprecated" diff --git a/cmd/manager/main.go b/cmd/manager/main.go index 17107866c..f6a1d561a 100644 --- a/cmd/manager/main.go +++ b/cmd/manager/main.go @@ -24,7 +24,6 @@ import ( "os" "time" - helmclient "github.com/operator-framework/helm-operator-plugins/pkg/client" "github.com/spf13/pflag" carvelv1alpha1 "github.com/vmware-tanzu/carvel-kapp-controller/pkg/apis/kappctrl/v1alpha1" "go.uber.org/zap/zapcore" @@ -38,6 +37,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/metrics/server" catalogd "github.com/operator-framework/catalogd/api/core/v1alpha1" + helmclient "github.com/operator-framework/helm-operator-plugins/pkg/client" rukpakv1alpha2 "github.com/operator-framework/rukpak/api/v1alpha2" ocv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1" diff --git a/internal/controllers/clusterextension_controller.go b/internal/controllers/clusterextension_controller.go index 2b86afe56..943cf8f57 100644 --- a/internal/controllers/clusterextension_controller.go +++ b/internal/controllers/clusterextension_controller.go @@ -25,16 +25,12 @@ import ( "sort" "strings" - "github.com/operator-framework/operator-controller/internal/rukpak/handler" - "github.com/operator-framework/operator-controller/internal/rukpak/util" - "helm.sh/helm/v3/pkg/postrender" - mmsemver "github.com/Masterminds/semver/v3" bsemver "github.com/blang/semver/v4" "github.com/go-logr/logr" + "helm.sh/helm/v3/pkg/postrender" "k8s.io/apimachinery/pkg/api/equality" apierrors "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/api/meta" apimeta "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" @@ -59,8 +55,10 @@ import ( catalogfilter "github.com/operator-framework/operator-controller/internal/catalogmetadata/filter" catalogsort "github.com/operator-framework/operator-controller/internal/catalogmetadata/sort" rukpakapi "github.com/operator-framework/operator-controller/internal/rukpak/api" + "github.com/operator-framework/operator-controller/internal/rukpak/handler" "github.com/operator-framework/operator-controller/internal/rukpak/source" "github.com/operator-framework/operator-controller/internal/rukpak/storage" + "github.com/operator-framework/operator-controller/internal/rukpak/util" ) // ClusterExtensionReconciler reconciles a ClusterExtension object @@ -181,7 +179,7 @@ func (r *ClusterExtensionReconciler) reconcile(ctx context.Context, ext *ocv1alp bundleFS, err := r.Storage.Load(ctx, ext) if err != nil { - meta.SetStatusCondition(&ext.Status.Conditions, metav1.Condition{ + apimeta.SetStatusCondition(&ext.Status.Conditions, metav1.Condition{ Type: ocv1alpha1.TypeHasValidBundle, Status: metav1.ConditionFalse, Reason: ocv1alpha1.ReasonBundleLoadFailed, @@ -192,7 +190,7 @@ func (r *ClusterExtensionReconciler) reconcile(ctx context.Context, ext *ocv1alp _, _, err = r.Handler.Handle(ctx, bundleFS, ext) if err != nil { - meta.SetStatusCondition(&ext.Status.Conditions, metav1.Condition{ + apimeta.SetStatusCondition(&ext.Status.Conditions, metav1.Condition{ Type: rukpakv1alpha2.TypeInstalled, Status: metav1.ConditionFalse, Reason: rukpakv1alpha2.ReasonInstallFailed, diff --git a/internal/controllers/clusterextension_status.go b/internal/controllers/clusterextension_status.go index 92b5ac5d1..f3ab31c5b 100644 --- a/internal/controllers/clusterextension_status.go +++ b/internal/controllers/clusterextension_status.go @@ -17,11 +17,12 @@ limitations under the License. package controllers import ( + "k8s.io/apimachinery/pkg/api/meta" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + ocv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1" rukpakapi "github.com/operator-framework/operator-controller/internal/rukpak/api" "github.com/operator-framework/operator-controller/internal/rukpak/source" - "k8s.io/apimachinery/pkg/api/meta" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) func updateStatusUnpackFailing(status *ocv1alpha1.ClusterExtensionStatus, err error) error { diff --git a/internal/rukpak/storage/localdir.go b/internal/rukpak/storage/localdir.go index e5c38086f..3c8de4253 100644 --- a/internal/rukpak/storage/localdir.go +++ b/internal/rukpak/storage/localdir.go @@ -14,8 +14,9 @@ import ( "path/filepath" "github.com/nlepage/go-tarfs" - "github.com/operator-framework/operator-controller/internal/rukpak/util" "sigs.k8s.io/controller-runtime/pkg/client" + + "github.com/operator-framework/operator-controller/internal/rukpak/util" ) var _ Storage = &LocalDirectory{} diff --git a/internal/rukpak/util/tar.go b/internal/rukpak/util/tar.go new file mode 100644 index 000000000..3226d4ea2 --- /dev/null +++ b/internal/rukpak/util/tar.go @@ -0,0 +1,63 @@ +package util + +import ( + "archive/tar" + "compress/gzip" + "fmt" + "io" + "io/fs" + "os" +) + +// FSToTarGZ writes the filesystem represented by fsys to w as a gzipped tar archive. +// This function unsets user and group information in the tar archive so that readers +// of archives produced by this function do not need to account for differences in +// permissions between source and destination filesystems. +func FSToTarGZ(w io.Writer, fsys fs.FS) error { + gzw := gzip.NewWriter(w) + tw := tar.NewWriter(gzw) + if err := fs.WalkDir(fsys, ".", func(path string, d fs.DirEntry, err error) error { + if err != nil { + return err + } + + if d.Type()&os.ModeSymlink != 0 { + return nil + } + info, err := d.Info() + if err != nil { + return fmt.Errorf("get file info for %q: %v", path, err) + } + + h, err := tar.FileInfoHeader(info, "") + if err != nil { + return fmt.Errorf("build tar file info header for %q: %v", path, err) + } + h.Uid = 0 + h.Gid = 0 + h.Uname = "" + h.Gname = "" + h.Name = path + + if err := tw.WriteHeader(h); err != nil { + return fmt.Errorf("write tar header for %q: %v", path, err) + } + if d.IsDir() { + return nil + } + f, err := fsys.Open(path) + if err != nil { + return fmt.Errorf("open file %q: %v", path, err) + } + if _, err := io.Copy(tw, f); err != nil { + return fmt.Errorf("write tar data for %q: %v", path, err) + } + return nil + }); err != nil { + return fmt.Errorf("generate tar.gz from FS: %v", err) + } + if err := tw.Close(); err != nil { + return err + } + return gzw.Close() +} diff --git a/internal/rukpak/util/util.go b/internal/rukpak/util/util.go index 132071d05..be1ef618c 100644 --- a/internal/rukpak/util/util.go +++ b/internal/rukpak/util/util.go @@ -1,11 +1,7 @@ package util import ( - "archive/tar" - "compress/gzip" - "fmt" "io" - "io/fs" "os" "k8s.io/cli-runtime/pkg/resource" @@ -40,59 +36,6 @@ func PodNamespace() string { return string(namespace) } -// FSToTarGZ writes the filesystem represented by fsys to w as a gzipped tar archive. -// This function unsets user and group information in the tar archive so that readers -// of archives produced by this function do not need to account for differences in -// permissions between source and destination filesystems. -func FSToTarGZ(w io.Writer, fsys fs.FS) error { - gzw := gzip.NewWriter(w) - tw := tar.NewWriter(gzw) - if err := fs.WalkDir(fsys, ".", func(path string, d fs.DirEntry, err error) error { - if err != nil { - return err - } - - if d.Type()&os.ModeSymlink != 0 { - return nil - } - info, err := d.Info() - if err != nil { - return fmt.Errorf("get file info for %q: %v", path, err) - } - - h, err := tar.FileInfoHeader(info, "") - if err != nil { - return fmt.Errorf("build tar file info header for %q: %v", path, err) - } - h.Uid = 0 - h.Gid = 0 - h.Uname = "" - h.Gname = "" - h.Name = path - - if err := tw.WriteHeader(h); err != nil { - return fmt.Errorf("write tar header for %q: %v", path, err) - } - if d.IsDir() { - return nil - } - f, err := fsys.Open(path) - if err != nil { - return fmt.Errorf("open file %q: %v", path, err) - } - if _, err := io.Copy(tw, f); err != nil { - return fmt.Errorf("write tar data for %q: %v", path, err) - } - return nil - }); err != nil { - return fmt.Errorf("generate tar.gz from FS: %v", err) - } - if err := tw.Close(); err != nil { - return err - } - return gzw.Close() -} - func ManifestObjects(r io.Reader, name string) ([]client.Object, error) { result := resource.NewLocalBuilder().Flatten().Unstructured().Stream(r, name).Do() if err := result.Err(); err != nil {