Skip to content

⚠️ A bit of cleanup #761

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/v1alpha1/clusterextension_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
12 changes: 5 additions & 7 deletions internal/controllers/clusterextension_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions internal/controllers/clusterextension_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion internal/rukpak/storage/localdir.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
63 changes: 63 additions & 0 deletions internal/rukpak/util/tar.go
Original file line number Diff line number Diff line change
@@ -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()
}
57 changes: 0 additions & 57 deletions internal/rukpak/util/util.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package util

import (
"archive/tar"
"compress/gzip"
"fmt"
"io"
"io/fs"
"os"

"k8s.io/cli-runtime/pkg/resource"
Expand Down Expand Up @@ -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 {
Expand Down