Skip to content

Commit fef0659

Browse files
committed
A bit of cleanup
Signed-off-by: Todd Short <[email protected]>
1 parent c353877 commit fef0659

File tree

7 files changed

+73
-65
lines changed

7 files changed

+73
-65
lines changed

api/v1alpha1/clusterextension_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ const (
8383
TypeInstalled = "Installed"
8484
TypeResolved = "Resolved"
8585
TypeHasValidBundle = "HasValidBundle"
86+
8687
// TypeDeprecated is a rollup condition that is present when
8788
// any of the deprecated conditions are present.
8889
TypeDeprecated = "Deprecated"

cmd/manager/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"os"
2525
"time"
2626

27-
helmclient "github.com/operator-framework/helm-operator-plugins/pkg/client"
2827
"github.com/spf13/pflag"
2928
carvelv1alpha1 "github.com/vmware-tanzu/carvel-kapp-controller/pkg/apis/kappctrl/v1alpha1"
3029
"go.uber.org/zap/zapcore"
@@ -38,6 +37,7 @@ import (
3837
"sigs.k8s.io/controller-runtime/pkg/metrics/server"
3938

4039
catalogd "github.com/operator-framework/catalogd/api/core/v1alpha1"
40+
helmclient "github.com/operator-framework/helm-operator-plugins/pkg/client"
4141
rukpakv1alpha2 "github.com/operator-framework/rukpak/api/v1alpha2"
4242

4343
ocv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"

internal/controllers/clusterextension_controller.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,10 @@ import (
2525
"sort"
2626
"strings"
2727

28-
"github.com/operator-framework/operator-controller/internal/rukpak/handler"
29-
"github.com/operator-framework/operator-controller/internal/rukpak/util"
30-
"helm.sh/helm/v3/pkg/postrender"
31-
3228
mmsemver "github.com/Masterminds/semver/v3"
3329
bsemver "github.com/blang/semver/v4"
3430
"github.com/go-logr/logr"
31+
"helm.sh/helm/v3/pkg/postrender"
3532
"k8s.io/apimachinery/pkg/api/equality"
3633
apierrors "k8s.io/apimachinery/pkg/api/errors"
3734
"k8s.io/apimachinery/pkg/api/meta"
@@ -59,8 +56,10 @@ import (
5956
catalogfilter "github.com/operator-framework/operator-controller/internal/catalogmetadata/filter"
6057
catalogsort "github.com/operator-framework/operator-controller/internal/catalogmetadata/sort"
6158
rukpakapi "github.com/operator-framework/operator-controller/internal/rukpak/api"
59+
"github.com/operator-framework/operator-controller/internal/rukpak/handler"
6260
"github.com/operator-framework/operator-controller/internal/rukpak/source"
6361
"github.com/operator-framework/operator-controller/internal/rukpak/storage"
62+
"github.com/operator-framework/operator-controller/internal/rukpak/util"
6463
)
6564

6665
// ClusterExtensionReconciler reconciles a ClusterExtension object

internal/controllers/clusterextension_status.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ limitations under the License.
1717
package controllers
1818

1919
import (
20+
"k8s.io/apimachinery/pkg/api/meta"
21+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
2023
ocv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
2124
rukpakapi "github.com/operator-framework/operator-controller/internal/rukpak/api"
2225
"github.com/operator-framework/operator-controller/internal/rukpak/source"
23-
"k8s.io/apimachinery/pkg/api/meta"
24-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2526
)
2627

2728
func updateStatusUnpackFailing(status *ocv1alpha1.ClusterExtensionStatus, err error) error {

internal/rukpak/storage/localdir.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ import (
1414
"path/filepath"
1515

1616
"github.com/nlepage/go-tarfs"
17-
"github.com/operator-framework/operator-controller/internal/rukpak/util"
1817
"sigs.k8s.io/controller-runtime/pkg/client"
18+
19+
"github.com/operator-framework/operator-controller/internal/rukpak/util"
1920
)
2021

2122
var _ Storage = &LocalDirectory{}

internal/rukpak/util/tar.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package util
2+
3+
import (
4+
"archive/tar"
5+
"compress/gzip"
6+
"fmt"
7+
"io"
8+
"io/fs"
9+
"os"
10+
)
11+
12+
// FSToTarGZ writes the filesystem represented by fsys to w as a gzipped tar archive.
13+
// This function unsets user and group information in the tar archive so that readers
14+
// of archives produced by this function do not need to account for differences in
15+
// permissions between source and destination filesystems.
16+
func FSToTarGZ(w io.Writer, fsys fs.FS) error {
17+
gzw := gzip.NewWriter(w)
18+
tw := tar.NewWriter(gzw)
19+
if err := fs.WalkDir(fsys, ".", func(path string, d fs.DirEntry, err error) error {
20+
if err != nil {
21+
return err
22+
}
23+
24+
if d.Type()&os.ModeSymlink != 0 {
25+
return nil
26+
}
27+
info, err := d.Info()
28+
if err != nil {
29+
return fmt.Errorf("get file info for %q: %v", path, err)
30+
}
31+
32+
h, err := tar.FileInfoHeader(info, "")
33+
if err != nil {
34+
return fmt.Errorf("build tar file info header for %q: %v", path, err)
35+
}
36+
h.Uid = 0
37+
h.Gid = 0
38+
h.Uname = ""
39+
h.Gname = ""
40+
h.Name = path
41+
42+
if err := tw.WriteHeader(h); err != nil {
43+
return fmt.Errorf("write tar header for %q: %v", path, err)
44+
}
45+
if d.IsDir() {
46+
return nil
47+
}
48+
f, err := fsys.Open(path)
49+
if err != nil {
50+
return fmt.Errorf("open file %q: %v", path, err)
51+
}
52+
if _, err := io.Copy(tw, f); err != nil {
53+
return fmt.Errorf("write tar data for %q: %v", path, err)
54+
}
55+
return nil
56+
}); err != nil {
57+
return fmt.Errorf("generate tar.gz from FS: %v", err)
58+
}
59+
if err := tw.Close(); err != nil {
60+
return err
61+
}
62+
return gzw.Close()
63+
}

internal/rukpak/util/util.go

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
package util
22

33
import (
4-
"archive/tar"
5-
"compress/gzip"
6-
"fmt"
74
"io"
8-
"io/fs"
95
"os"
106

117
"k8s.io/cli-runtime/pkg/resource"
@@ -40,59 +36,6 @@ func PodNamespace() string {
4036
return string(namespace)
4137
}
4238

43-
// FSToTarGZ writes the filesystem represented by fsys to w as a gzipped tar archive.
44-
// This function unsets user and group information in the tar archive so that readers
45-
// of archives produced by this function do not need to account for differences in
46-
// permissions between source and destination filesystems.
47-
func FSToTarGZ(w io.Writer, fsys fs.FS) error {
48-
gzw := gzip.NewWriter(w)
49-
tw := tar.NewWriter(gzw)
50-
if err := fs.WalkDir(fsys, ".", func(path string, d fs.DirEntry, err error) error {
51-
if err != nil {
52-
return err
53-
}
54-
55-
if d.Type()&os.ModeSymlink != 0 {
56-
return nil
57-
}
58-
info, err := d.Info()
59-
if err != nil {
60-
return fmt.Errorf("get file info for %q: %v", path, err)
61-
}
62-
63-
h, err := tar.FileInfoHeader(info, "")
64-
if err != nil {
65-
return fmt.Errorf("build tar file info header for %q: %v", path, err)
66-
}
67-
h.Uid = 0
68-
h.Gid = 0
69-
h.Uname = ""
70-
h.Gname = ""
71-
h.Name = path
72-
73-
if err := tw.WriteHeader(h); err != nil {
74-
return fmt.Errorf("write tar header for %q: %v", path, err)
75-
}
76-
if d.IsDir() {
77-
return nil
78-
}
79-
f, err := fsys.Open(path)
80-
if err != nil {
81-
return fmt.Errorf("open file %q: %v", path, err)
82-
}
83-
if _, err := io.Copy(tw, f); err != nil {
84-
return fmt.Errorf("write tar data for %q: %v", path, err)
85-
}
86-
return nil
87-
}); err != nil {
88-
return fmt.Errorf("generate tar.gz from FS: %v", err)
89-
}
90-
if err := tw.Close(); err != nil {
91-
return err
92-
}
93-
return gzw.Close()
94-
}
95-
9639
func ManifestObjects(r io.Reader, name string) ([]client.Object, error) {
9740
result := resource.NewLocalBuilder().Flatten().Unstructured().Stream(r, name).Do()
9841
if err := result.Err(); err != nil {

0 commit comments

Comments
 (0)