Merge pull request #31389 from TerryHowe/chore-more-registry-clean-up

chore: fix pkg/registry warnings to reduce noise
pull/31415/head
George Jenkins 11 months ago committed by GitHub
commit bdc459d73c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -236,12 +236,12 @@ func TestGenerateOCICreatedAnnotations(t *testing.T) {
nowTime := time.Now() nowTime := time.Now()
nowTimeString := nowTime.Format(time.RFC3339) nowTimeString := nowTime.Format(time.RFC3339)
chart := &chart.Metadata{ testChart := &chart.Metadata{
Name: "oci", Name: "oci",
Version: "0.0.1", Version: "0.0.1",
} }
result := generateOCIAnnotations(chart, nowTimeString) result := generateOCIAnnotations(testChart, nowTimeString)
// Check that created annotation exists // Check that created annotation exists
if _, ok := result[ocispec.AnnotationCreated]; !ok { if _, ok := result[ocispec.AnnotationCreated]; !ok {
@ -254,7 +254,7 @@ func TestGenerateOCICreatedAnnotations(t *testing.T) {
} }
// Verify default creation time set // Verify default creation time set
result = generateOCIAnnotations(chart, "") result = generateOCIAnnotations(testChart, "")
// Check that created annotation exists // Check that created annotation exists
if _, ok := result[ocispec.AnnotationCreated]; !ok { if _, ok := result[ocispec.AnnotationCreated]; !ok {

@ -255,7 +255,7 @@ func (c *Client) Login(host string, options ...LoginOption) error {
return err return err
} }
fmt.Fprintln(c.out, "Login Succeeded") _, _ = fmt.Fprintln(c.out, "Login Succeeded")
return nil return nil
} }
@ -383,7 +383,7 @@ func (c *Client) Logout(host string, opts ...LogoutOption) error {
if err := credentials.Logout(context.Background(), c.credentialsStore, host); err != nil { if err := credentials.Logout(context.Background(), c.credentialsStore, host); err != nil {
return err return err
} }
fmt.Fprintf(c.out, "Removing login credentials for %s\n", host) _, _ = fmt.Fprintf(c.out, "Removing login credentials for %s\n", host)
return nil return nil
} }
@ -453,7 +453,7 @@ func (c *Client) processChartPull(genericResult *GenericPullResult, operation *p
provDescriptor = &d provDescriptor = &d
case LegacyChartLayerMediaType: case LegacyChartLayerMediaType:
chartDescriptor = &d chartDescriptor = &d
fmt.Fprintf(c.out, "Warning: chart media type %s is deprecated\n", LegacyChartLayerMediaType) _, _ = fmt.Fprintf(c.out, "Warning: chart media type %s is deprecated\n", LegacyChartLayerMediaType)
} }
} }
@ -526,12 +526,12 @@ func (c *Client) processChartPull(genericResult *GenericPullResult, operation *p
result.Prov.Size = provDescriptor.Size result.Prov.Size = provDescriptor.Size
} }
fmt.Fprintf(c.out, "Pulled: %s\n", result.Ref) _, _ = fmt.Fprintf(c.out, "Pulled: %s\n", result.Ref)
fmt.Fprintf(c.out, "Digest: %s\n", result.Manifest.Digest) _, _ = fmt.Fprintf(c.out, "Digest: %s\n", result.Manifest.Digest)
if strings.Contains(result.Ref, "_") { if strings.Contains(result.Ref, "_") {
fmt.Fprintf(c.out, "%s contains an underscore.\n", result.Ref) _, _ = fmt.Fprintf(c.out, "%s contains an underscore.\n", result.Ref)
fmt.Fprint(c.out, registryUnderscoreMessage+"\n") _, _ = fmt.Fprint(c.out, registryUnderscoreMessage+"\n")
} }
return result, nil return result, nil
@ -728,11 +728,11 @@ func (c *Client) Push(data []byte, ref string, options ...PushOption) (*PushResu
Size: provDescriptor.Size, Size: provDescriptor.Size,
} }
} }
fmt.Fprintf(c.out, "Pushed: %s\n", result.Ref) _, _ = fmt.Fprintf(c.out, "Pushed: %s\n", result.Ref)
fmt.Fprintf(c.out, "Digest: %s\n", result.Manifest.Digest) _, _ = fmt.Fprintf(c.out, "Digest: %s\n", result.Manifest.Digest)
if strings.Contains(parsedRef.orasReference.Reference, "_") { if strings.Contains(parsedRef.orasReference.Reference, "_") {
fmt.Fprintf(c.out, "%s contains an underscore.\n", result.Ref) _, _ = fmt.Fprintf(c.out, "%s contains an underscore.\n", result.Ref)
fmt.Fprint(c.out, registryUnderscoreMessage+"\n") _, _ = fmt.Fprint(c.out, registryUnderscoreMessage+"\n")
} }
return result, err return result, err

@ -37,7 +37,7 @@ func (suite *HTTPRegistryClientTestSuite) SetupSuite() {
func (suite *HTTPRegistryClientTestSuite) TearDownSuite() { func (suite *HTTPRegistryClientTestSuite) TearDownSuite() {
teardown(&suite.TestRegistry) teardown(&suite.TestRegistry)
os.RemoveAll(suite.WorkspaceDir) _ = os.RemoveAll(suite.WorkspaceDir)
} }
func (suite *HTTPRegistryClientTestSuite) Test_0_Login() { func (suite *HTTPRegistryClientTestSuite) Test_0_Login() {

@ -34,7 +34,7 @@ func (suite *InsecureTLSRegistryClientTestSuite) SetupSuite() {
func (suite *InsecureTLSRegistryClientTestSuite) TearDownSuite() { func (suite *InsecureTLSRegistryClientTestSuite) TearDownSuite() {
teardown(&suite.TestRegistry) teardown(&suite.TestRegistry)
os.RemoveAll(suite.WorkspaceDir) _ = os.RemoveAll(suite.WorkspaceDir)
} }
func (suite *InsecureTLSRegistryClientTestSuite) Test_0_Login() { func (suite *InsecureTLSRegistryClientTestSuite) Test_0_Login() {

@ -36,7 +36,7 @@ func (suite *TLSRegistryClientTestSuite) SetupSuite() {
func (suite *TLSRegistryClientTestSuite) TearDownSuite() { func (suite *TLSRegistryClientTestSuite) TearDownSuite() {
teardown(&suite.TestRegistry) teardown(&suite.TestRegistry)
os.RemoveAll(suite.WorkspaceDir) _ = os.RemoveAll(suite.WorkspaceDir)
} }
func (suite *TLSRegistryClientTestSuite) Test_0_Login() { func (suite *TLSRegistryClientTestSuite) Test_0_Login() {

@ -92,7 +92,7 @@ func (c *GenericClient) PullGeneric(ref string, options GenericPullOptions) (*Ge
memoryStore := memory.New() memoryStore := memory.New()
var descriptors []ocispec.Descriptor var descriptors []ocispec.Descriptor
// Set up repository with authentication and configuration // Set up a repository with authentication and configuration
repository, err := remote.NewRepository(parsedRef.String()) repository, err := remote.NewRepository(parsedRef.String())
if err != nil { if err != nil {
return nil, err return nil, err
@ -114,7 +114,7 @@ func (c *GenericClient) PullGeneric(ref string, options GenericPullOptions) (*Ge
manifest, err := oras.Copy(ctx, repository, parsedRef.String(), memoryStore, "", oras.CopyOptions{ manifest, err := oras.Copy(ctx, repository, parsedRef.String(), memoryStore, "", oras.CopyOptions{
CopyGraphOptions: oras.CopyGraphOptions{ CopyGraphOptions: oras.CopyGraphOptions{
PreCopy: func(ctx context.Context, desc ocispec.Descriptor) error { PreCopy: func(ctx context.Context, desc ocispec.Descriptor) error {
// Apply custom PreCopy function if provided // Apply a custom PreCopy function if provided
if options.PreCopy != nil { if options.PreCopy != nil {
if err := options.PreCopy(ctx, desc); err != nil { if err := options.PreCopy(ctx, desc); err != nil {
return err return err

@ -147,15 +147,15 @@ func (c *Client) processPluginPull(genericResult *GenericPullResult, pluginName
} }
} }
fmt.Fprintf(c.out, "Pulled plugin: %s\n", result.Ref) _, _ = fmt.Fprintf(c.out, "Pulled plugin: %s\n", result.Ref)
fmt.Fprintf(c.out, "Digest: %s\n", result.Manifest.Digest) _, _ = fmt.Fprintf(c.out, "Digest: %s\n", result.Manifest.Digest)
if result.Prov.Data != nil { if result.Prov.Data != nil {
fmt.Fprintf(c.out, "Provenance: %s\n", foundProvenanceName) _, _ = fmt.Fprintf(c.out, "Provenance: %s\n", foundProvenanceName)
} }
if strings.Contains(result.Ref, "_") { if strings.Contains(result.Ref, "_") {
fmt.Fprintf(c.out, "%s contains an underscore.\n", result.Ref) _, _ = fmt.Fprintf(c.out, "%s contains an underscore.\n", result.Ref)
fmt.Fprint(c.out, registryUnderscoreMessage+"\n") _, _ = fmt.Fprint(c.out, registryUnderscoreMessage+"\n")
} }
return result, nil return result, nil

@ -32,11 +32,11 @@ type reference struct {
} }
// newReference will parse and validate the reference, and clean tags when // newReference will parse and validate the reference, and clean tags when
// applicable tags are only cleaned when plus (+) signs are present, and are // applicable tags are only cleaned when plus (+) signs are present and are
// converted to underscores (_) before pushing // converted to underscores (_) before pushing
// See https://github.com/helm/helm/issues/10166 // See https://github.com/helm/helm/issues/10166
func newReference(raw string) (result reference, err error) { func newReference(raw string) (result reference, err error) {
// Remove oci:// prefix if it is there // Remove the oci:// prefix if it is there
raw = strings.TrimPrefix(raw, OCIScheme+"://") raw = strings.TrimPrefix(raw, OCIScheme+"://")
// The sole possible reference modification is replacing plus (+) signs // The sole possible reference modification is replacing plus (+) signs

@ -35,6 +35,7 @@ import (
"github.com/distribution/distribution/v3/registry" "github.com/distribution/distribution/v3/registry"
_ "github.com/distribution/distribution/v3/registry/auth/htpasswd" _ "github.com/distribution/distribution/v3/registry/auth/htpasswd"
_ "github.com/distribution/distribution/v3/registry/storage/driver/inmemory" _ "github.com/distribution/distribution/v3/registry/storage/driver/inmemory"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
"golang.org/x/crypto/bcrypt" "golang.org/x/crypto/bcrypt"
@ -68,13 +69,13 @@ type TestRegistry struct {
func setup(suite *TestRegistry, tlsEnabled, insecure bool) { func setup(suite *TestRegistry, tlsEnabled, insecure bool) {
suite.WorkspaceDir = testWorkspaceDir suite.WorkspaceDir = testWorkspaceDir
os.RemoveAll(suite.WorkspaceDir) err := os.RemoveAll(suite.WorkspaceDir)
os.Mkdir(suite.WorkspaceDir, 0700) require.NoError(suite.T(), err, "no error removing test workspace dir")
err = os.Mkdir(suite.WorkspaceDir, 0700)
require.NoError(suite.T(), err, "no error creating test workspace dir")
var out bytes.Buffer
var (
out bytes.Buffer
err error
)
suite.Out = &out suite.Out = &out
credentialsFile := filepath.Join(suite.WorkspaceDir, CredentialsFileBasename) credentialsFile := filepath.Join(suite.WorkspaceDir, CredentialsFileBasename)
@ -124,7 +125,7 @@ func setup(suite *TestRegistry, tlsEnabled, insecure bool) {
config := &configuration.Configuration{} config := &configuration.Configuration{}
ln, err := net.Listen("tcp", "127.0.0.1:0") ln, err := net.Listen("tcp", "127.0.0.1:0")
suite.Nil(err, "no error finding free port for test registry") suite.Nil(err, "no error finding free port for test registry")
defer ln.Close() defer func() { _ = ln.Close() }()
// Change the registry host to another host which is not localhost. // Change the registry host to another host which is not localhost.
// This is required because Docker enforces HTTP if the registry // This is required because Docker enforces HTTP if the registry
@ -176,7 +177,7 @@ func initCompromisedRegistryTestServer() string {
w.Header().Set("Content-Type", "application/vnd.oci.image.manifest.v1+json") w.Header().Set("Content-Type", "application/vnd.oci.image.manifest.v1+json")
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, `{ "schemaVersion": 2, "config": { _, _ = fmt.Fprintf(w, `{ "schemaVersion": 2, "config": {
"mediaType": "%s", "mediaType": "%s",
"digest": "sha256:a705ee2789ab50a5ba20930f246dbd5cc01ff9712825bb98f57ee8414377f133", "digest": "sha256:a705ee2789ab50a5ba20930f246dbd5cc01ff9712825bb98f57ee8414377f133",
"size": 181 "size": 181
@ -192,13 +193,13 @@ func initCompromisedRegistryTestServer() string {
} else if r.URL.Path == "/v2/testrepo/supposedlysafechart/blobs/sha256:a705ee2789ab50a5ba20930f246dbd5cc01ff9712825bb98f57ee8414377f133" { } else if r.URL.Path == "/v2/testrepo/supposedlysafechart/blobs/sha256:a705ee2789ab50a5ba20930f246dbd5cc01ff9712825bb98f57ee8414377f133" {
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
w.Write([]byte("{\"name\":\"mychart\",\"version\":\"0.1.0\",\"description\":\"A Helm chart for Kubernetes\\n" + _, _ = w.Write([]byte("{\"name\":\"mychart\",\"version\":\"0.1.0\",\"description\":\"A Helm chart for Kubernetes\\n" +
"an 'application' or a 'library' chart.\",\"apiVersion\":\"v2\",\"appVersion\":\"1.16.0\",\"type\":" + "an 'application' or a 'library' chart.\",\"apiVersion\":\"v2\",\"appVersion\":\"1.16.0\",\"type\":" +
"\"application\"}")) "\"application\"}"))
} else if r.URL.Path == "/v2/testrepo/supposedlysafechart/blobs/sha256:ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb" { } else if r.URL.Path == "/v2/testrepo/supposedlysafechart/blobs/sha256:ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb" {
w.Header().Set("Content-Type", ChartLayerMediaType) w.Header().Set("Content-Type", ChartLayerMediaType)
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
w.Write([]byte("b")) _, _ = w.Write([]byte("b"))
} else { } else {
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
} }

@ -25,10 +25,10 @@ import (
func GetTagMatchingVersionOrConstraint(tags []string, versionString string) (string, error) { func GetTagMatchingVersionOrConstraint(tags []string, versionString string) (string, error) {
var constraint *semver.Constraints var constraint *semver.Constraints
if versionString == "" { if versionString == "" {
// If string is empty, set wildcard constraint // If the string is empty, set a wildcard constraint
constraint, _ = semver.NewConstraint("*") constraint, _ = semver.NewConstraint("*")
} else { } else {
// when customer inputs specific version, check whether there's an exact match first // when customer inputs a specific version, check whether there's an exact match first
for _, v := range tags { for _, v := range tags {
if versionString == v { if versionString == v {
return v, nil return v, nil

@ -97,7 +97,7 @@ func (t *LoggingTransport) RoundTrip(req *http.Request) (resp *http.Response, er
// logHeader prints out the provided header keys and values, with auth header scrubbed. // logHeader prints out the provided header keys and values, with auth header scrubbed.
func logHeader(header http.Header) string { func logHeader(header http.Header) string {
if len(header) > 0 { if len(header) > 0 {
headers := []string{} var headers []string
for k, v := range header { for k, v := range header {
for _, h := range toScrub { for _, h := range toScrub {
if strings.EqualFold(k, h) { if strings.EqualFold(k, h) {

Loading…
Cancel
Save