Skip to content

Commit

Permalink
standardize consts (#353)
Browse files Browse the repository at this point in the history
* removed k3s code
* standardize and formatted consts
* fixed consts for sync.go
* trying another fix for sync

---------

Signed-off-by: Zack Brady <[email protected]>
  • Loading branch information
zackbradys authored Nov 6, 2024
1 parent 2fa6c36 commit 38c7d1b
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 99 deletions.
3 changes: 2 additions & 1 deletion cmd/hauler/cli/store/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/google/go-containerregistry/pkg/name"
"hauler.dev/go/hauler/pkg/artifacts/file/getter"
"hauler.dev/go/hauler/pkg/consts"
"helm.sh/helm/v3/pkg/action"

"hauler.dev/go/hauler/internal/flags"
Expand Down Expand Up @@ -35,7 +36,7 @@ func storeFile(ctx context.Context, s *store.Layout, fi v1alpha1.File) error {
}

f := file.NewFile(fi.Path, file.WithClient(getter.NewClient(copts)))
ref, err := reference.NewTagged(f.Name(fi.Path), reference.DefaultTag)
ref, err := reference.NewTagged(f.Name(fi.Path), consts.DefaultTag)
if err != nil {
return err
}
Expand Down
12 changes: 6 additions & 6 deletions cmd/hauler/cli/store/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func processContent(ctx context.Context, fi *os.File, o *flags.SyncOpts, s *stor

// TODO: Should type switch instead...
switch obj.GroupVersionKind().Kind {
case v1alpha1.FilesContentKind:
case consts.FilesContentKind:
var cfg v1alpha1.Files
if err := yaml.Unmarshal(doc, &cfg); err != nil {
return err
Expand All @@ -122,7 +122,7 @@ func processContent(ctx context.Context, fi *os.File, o *flags.SyncOpts, s *stor
}
}

case v1alpha1.ImagesContentKind:
case consts.ImagesContentKind:
var cfg v1alpha1.Images
if err := yaml.Unmarshal(doc, &cfg); err != nil {
return err
Expand Down Expand Up @@ -196,7 +196,7 @@ func processContent(ctx context.Context, fi *os.File, o *flags.SyncOpts, s *stor
// sync with local index
s.CopyAll(ctx, s.OCI, nil)

case v1alpha1.ChartsContentKind:
case consts.ChartsContentKind:
var cfg v1alpha1.Charts
if err := yaml.Unmarshal(doc, &cfg); err != nil {
return err
Expand All @@ -210,7 +210,7 @@ func processContent(ctx context.Context, fi *os.File, o *flags.SyncOpts, s *stor
}
}

case v1alpha1.ChartsCollectionKind:
case consts.ChartsCollectionKind:
var cfg v1alpha1.ThickCharts
if err := yaml.Unmarshal(doc, &cfg); err != nil {
return err
Expand All @@ -230,7 +230,7 @@ func processContent(ctx context.Context, fi *os.File, o *flags.SyncOpts, s *stor
}
}

case v1alpha1.ImageTxtsContentKind:
case consts.ImageTxtsContentKind:
var cfg v1alpha1.ImageTxts
if err := yaml.Unmarshal(doc, &cfg); err != nil {
return err
Expand All @@ -251,7 +251,7 @@ func processContent(ctx context.Context, fi *os.File, o *flags.SyncOpts, s *stor
}

default:
return fmt.Errorf("unrecognized content/collection type: %s", obj.GroupVersionKind().String())
return fmt.Errorf("unrecognized content or collection type: %s", obj.GroupVersionKind().String())
}
}
return nil
Expand Down
37 changes: 18 additions & 19 deletions internal/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ import (
"time"

"github.com/common-nighthawk/go-figure"
"hauler.dev/go/hauler/pkg/consts"
)

const unknown = "unknown"

// Base version information.
//
// This is the fallback data used when version information from git is not
Expand All @@ -41,19 +40,19 @@ var (
// branch should be tagged using the correct versioning strategy.
gitVersion = "devel"
// SHA1 from git, output of $(git rev-parse HEAD)
gitCommit = unknown
gitCommit = consts.Unknown
// State of git tree, either "clean" or "dirty"
gitTreeState = unknown
gitTreeState = consts.Unknown
// Build date in ISO8601 format, output of $(date -u +'%Y-%m-%dT%H:%M:%SZ')
buildDate = unknown
buildDate = consts.Unknown
// flag to print the ascii name banner
asciiName = "true"
// goVersion is the used golang version.
goVersion = unknown
goVersion = consts.Unknown
// compiler is the used golang compiler.
compiler = unknown
compiler = consts.Unknown
// platform is the used os/arch identifier.
platform = unknown
platform = consts.Unknown

once sync.Once
info = Info{}
Expand Down Expand Up @@ -84,7 +83,7 @@ func getBuildInfo() *debug.BuildInfo {

func getGitVersion(bi *debug.BuildInfo) string {
if bi == nil {
return unknown
return consts.Unknown
}

// TODO: remove this when the issue https://github.com/golang/go/issues/29228 is fixed
Expand All @@ -107,56 +106,56 @@ func getDirty(bi *debug.BuildInfo) string {
if modified == "false" {
return "clean"
}
return unknown
return consts.Unknown
}

func getBuildDate(bi *debug.BuildInfo) string {
buildTime := getKey(bi, "vcs.time")
t, err := time.Parse("2006-01-02T15:04:05Z", buildTime)
if err != nil {
return unknown
return consts.Unknown
}
return t.Format("2006-01-02T15:04:05")
}

func getKey(bi *debug.BuildInfo, key string) string {
if bi == nil {
return unknown
return consts.Unknown
}
for _, iter := range bi.Settings {
if iter.Key == key {
return iter.Value
}
}
return unknown
return consts.Unknown
}

// GetVersionInfo represents known information on how this binary was built.
func GetVersionInfo() Info {
once.Do(func() {
buildInfo := getBuildInfo()
gitVersion = getGitVersion(buildInfo)
if gitCommit == unknown {
if gitCommit == consts.Unknown {
gitCommit = getCommit(buildInfo)
}

if gitTreeState == unknown {
if gitTreeState == consts.Unknown {
gitTreeState = getDirty(buildInfo)
}

if buildDate == unknown {
if buildDate == consts.Unknown {
buildDate = getBuildDate(buildInfo)
}

if goVersion == unknown {
if goVersion == consts.Unknown {
goVersion = runtime.Version()
}

if compiler == unknown {
if compiler == consts.Unknown {
compiler = runtime.Compiler
}

if platform == unknown {
if platform == consts.Unknown {
platform = fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH)
}

Expand Down
5 changes: 0 additions & 5 deletions pkg/apis/hauler.cattle.io/v1alpha1/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const (
ChartsContentKind = "Charts"
ChartsCollectionKind = "ThickCharts"
)

type Charts struct {
*metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down
4 changes: 0 additions & 4 deletions pkg/apis/hauler.cattle.io/v1alpha1/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const (
DriverContentKind = "Driver"
)

type Driver struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down
2 changes: 0 additions & 2 deletions pkg/apis/hauler.cattle.io/v1alpha1/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const FilesContentKind = "Files"

type Files struct {
*metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down
13 changes: 3 additions & 10 deletions pkg/apis/hauler.cattle.io/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
package v1alpha1

import (
"hauler.dev/go/hauler/pkg/consts"
"k8s.io/apimachinery/pkg/runtime/schema"
)

const (
Version = "v1alpha1"
ContentGroup = "content.hauler.cattle.io"
CollectionGroup = "collection.hauler.cattle.io"
)

var (
ContentGroupVersion = schema.GroupVersion{Group: ContentGroup, Version: Version}
// SchemeBuilder = &scheme.Builder{GroupVersion: ContentGroupVersion}

CollectionGroupVersion = schema.GroupVersion{Group: CollectionGroup, Version: Version}
ContentGroupVersion = schema.GroupVersion{Group: consts.ContentGroup, Version: consts.APIVersion}
CollectionGroupVersion = schema.GroupVersion{Group: consts.CollectionGroup, Version: consts.APIVersion}
)
2 changes: 0 additions & 2 deletions pkg/apis/hauler.cattle.io/v1alpha1/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const ImagesContentKind = "Images"

type Images struct {
*metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down
4 changes: 0 additions & 4 deletions pkg/apis/hauler.cattle.io/v1alpha1/imagetxt.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const (
ImageTxtsContentKind = "ImageTxts"
)

type ImageTxts struct {
*metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down
73 changes: 43 additions & 30 deletions pkg/consts/consts.go
Original file line number Diff line number Diff line change
@@ -1,60 +1,73 @@
package consts

const (
// container media types
OCIManifestSchema1 = "application/vnd.oci.image.manifest.v1+json"
DockerManifestSchema2 = "application/vnd.docker.distribution.manifest.v2+json"
DockerManifestListSchema2 = "application/vnd.docker.distribution.manifest.list.v2+json"
OCIImageIndexSchema = "application/vnd.oci.image.index.v1+json"
DockerConfigJSON = "application/vnd.docker.container.image.v1+json"
DockerLayer = "application/vnd.docker.image.rootfs.diff.tar.gzip"
DockerForeignLayer = "application/vnd.docker.image.rootfs.foreign.diff.tar.gzip"
DockerUncompressedLayer = "application/vnd.docker.image.rootfs.diff.tar"
OCILayer = "application/vnd.oci.image.layer.v1.tar+gzip"
OCIArtifact = "application/vnd.oci.empty.v1+json"

DockerConfigJSON = "application/vnd.docker.container.image.v1+json"
DockerLayer = "application/vnd.docker.image.rootfs.diff.tar.gzip"
DockerForeignLayer = "application/vnd.docker.image.rootfs.foreign.diff.tar.gzip"
DockerUncompressedLayer = "application/vnd.docker.image.rootfs.diff.tar"
OCILayer = "application/vnd.oci.image.layer.v1.tar+gzip"
OCIArtifact = "application/vnd.oci.empty.v1+json"

// ChartConfigMediaType is the reserved media type for the Helm chart manifest config
// helm chart media types
ChartConfigMediaType = "application/vnd.cncf.helm.config.v1+json"
ChartLayerMediaType = "application/vnd.cncf.helm.chart.content.v1.tar+gzip"
ProvLayerMediaType = "application/vnd.cncf.helm.chart.provenance.v1.prov"

// ChartLayerMediaType is the reserved media type for Helm chart package content
ChartLayerMediaType = "application/vnd.cncf.helm.chart.content.v1.tar+gzip"

// ProvLayerMediaType is the reserved media type for Helm chart provenance files
ProvLayerMediaType = "application/vnd.cncf.helm.chart.provenance.v1.prov"

// FileLayerMediaType is the reserved media type for File content layers
FileLayerMediaType = "application/vnd.content.hauler.file.layer.v1"

// FileLocalConfigMediaType is the reserved media type for File config
// file media types
FileLayerMediaType = "application/vnd.content.hauler.file.layer.v1"
FileLocalConfigMediaType = "application/vnd.content.hauler.file.local.config.v1+json"
FileDirectoryConfigMediaType = "application/vnd.content.hauler.file.directory.config.v1+json"
FileHttpConfigMediaType = "application/vnd.content.hauler.file.http.config.v1+json"

// MemoryConfigMediaType is the reserved media type for Memory config for a generic set of bytes stored in memory
// memory media types
MemoryConfigMediaType = "application/vnd.content.hauler.memory.config.v1+json"

// WasmArtifactLayerMediaType is the reserved media type for WASM artifact layers
// wasm media types
WasmArtifactLayerMediaType = "application/vnd.wasm.content.layer.v1+wasm"
WasmConfigMediaType = "application/vnd.wasm.config.v1+json"

// WasmConfigMediaType is the reserved media type for WASM configs
WasmConfigMediaType = "application/vnd.wasm.config.v1+json"

// unknown media types
UnknownManifest = "application/vnd.hauler.cattle.io.unknown.v1+json"
UnknownLayer = "application/vnd.content.hauler.unknown.layer"
Unknown = "unknown"

// vendor prefixes
OCIVendorPrefix = "vnd.oci"
DockerVendorPrefix = "vnd.docker"
HaulerVendorPrefix = "vnd.hauler"
OCIImageIndexFile = "index.json"

KindAnnotationName = "kind"
KindAnnotationImage = "dev.cosignproject.cosign/image"
KindAnnotationIndex = "dev.cosignproject.cosign/imageIndex"

CarbideRegistry = "rgcrprod.azurecr.us"
// annotation keys
KindAnnotationName = "kind"
KindAnnotationImage = "dev.cosignproject.cosign/image"
KindAnnotationIndex = "dev.cosignproject.cosign/imageIndex"
ImageAnnotationKey = "hauler.dev/key"
ImageAnnotationPlatform = "hauler.dev/platform"
ImageAnnotationRegistry = "hauler.dev/registry"

DefaultStoreName = "store"
// content kinds
ImagesContentKind = "Images"
ChartsContentKind = "Charts"
FilesContentKind = "Files"
DriverContentKind = "Driver"
ImageTxtsContentKind = "ImageTxts"
ChartsCollectionKind = "ThickCharts"

// content groups
ContentGroup = "content.hauler.cattle.io"
CollectionGroup = "collection.hauler.cattle.io"

// other constraints
CarbideRegistry = "rgcrprod.azurecr.us"
APIVersion = "v1alpha1"
DefaultNamespace = "hauler"
DefaultTag = "latest"
DefaultStoreName = "store"
DefaultRetries = 3
RetriesInterval = 5
OCIImageIndexFile = "index.json"
)
Loading

0 comments on commit 38c7d1b

Please sign in to comment.