From 28fa846514b1a322adbedd8370814004c7d4fa34 Mon Sep 17 00:00:00 2001 From: Eric Stroczynski Date: Tue, 10 Dec 2019 11:28:33 -0800 Subject: [PATCH 1/6] internal/olm/operator/internal: tools to create and delete a manifest registry --- internal/olm/operator/internal/configmap.go | 152 ++++++++++++++++ internal/olm/operator/internal/deployment.go | 176 +++++++++++++++++++ internal/olm/operator/internal/registry.go | 98 +++++++++++ internal/olm/operator/internal/service.go | 57 ++++++ 4 files changed, 483 insertions(+) create mode 100644 internal/olm/operator/internal/configmap.go create mode 100644 internal/olm/operator/internal/deployment.go create mode 100644 internal/olm/operator/internal/registry.go create mode 100644 internal/olm/operator/internal/service.go diff --git a/internal/olm/operator/internal/configmap.go b/internal/olm/operator/internal/configmap.go new file mode 100644 index 00000000000..dedd304c213 --- /dev/null +++ b/internal/olm/operator/internal/configmap.go @@ -0,0 +1,152 @@ +// Copyright 2019 The Operator-SDK Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package olm + +import ( + "context" + "crypto/md5" + "encoding/base32" + "fmt" + "strings" + + "github.com/operator-framework/operator-sdk/internal/util/k8sutil" + + "github.com/ghodss/yaml" + "github.com/operator-framework/operator-registry/pkg/registry" + "github.com/pkg/errors" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" +) + +const ( + // The directory containing all manifests for an operator, with the + // package manifest being top-level. + containerManifestsDir = "/registry/manifests" +) + +// IsManifestDataStale checks if manifest data stored in the registry is stale +// by comparing it to manifest data currently managed by m. +func (m *RegistryResources) IsManifestDataStale(ctx context.Context, namespace string) (bool, error) { + pkg := m.Manifests.GetPackageManifest() + pkgName := pkg.PackageName + nn := types.NamespacedName{ + Name: getRegistryConfigMapName(pkgName), + Namespace: namespace, + } + configmap := corev1.ConfigMap{} + err := m.Client.KubeClient.Get(ctx, nn, &configmap) + if err != nil { + return false, err + } + // Collect digests of manifests submitted to m. + newData, err := createConfigMapBinaryData(pkg, m.Manifests.GetBundles()) + if err != nil { + return false, errors.Wrap(err, "error creating binary data") + } + // If the number of files to be added to the registry don't match the number + // of files currently in the registry, we have added or removed a file. + if len(newData) != len(configmap.BinaryData) { + return true, nil + } + // Check each binary value's key, which contains a base32-encoded md5 digest + // component, against the new set of manifest keys. + for fileKey := range configmap.BinaryData { + if _, match := newData[fileKey]; !match { + return true, nil + } + } + return false, nil +} + +// hashContents creates a base32-encoded md5 digest of b's bytes. +func hashContents(b []byte) string { + h := md5.New() + _, _ = h.Write(b) + enc := base32.StdEncoding.WithPadding(base32.NoPadding) + return enc.EncodeToString(h.Sum(nil)) +} + +// getObjectFileName opaquely creates a unique file name based on data in b. +func getObjectFileName(b []byte, name, kind string) string { + digest := hashContents(b) + return fmt.Sprintf("%s.%s.%s.yaml", digest, name, strings.ToLower(kind)) +} + +func getPackageFileName(b []byte, name string) string { + digest := hashContents(b) + return fmt.Sprintf("%s.%s.package.yaml", digest, name) +} + +// createConfigMapBinaryData opaquely creates a set of paths using data in pkg +// and each bundle in bundles, unique by path. These paths are intended to +// be keys in a ConfigMap. +func createConfigMapBinaryData(pkg registry.PackageManifest, bundles []*registry.Bundle) (map[string][]byte, error) { + pkgName := pkg.PackageName + binaryKeyValues := map[string][]byte{} + pb, err := yaml.Marshal(pkg) + if err != nil { + return nil, errors.Wrapf(err, "error marshalling package manifest %s", pkgName) + } + binaryKeyValues[getPackageFileName(pb, pkgName)] = pb + for _, bundle := range bundles { + for _, o := range bundle.Objects { + ob, err := yaml.Marshal(o) + if err != nil { + return nil, errors.Wrapf(err, "error marshalling object %s %q", o.GroupVersionKind(), o.GetName()) + } + binaryKeyValues[getObjectFileName(ob, o.GetName(), o.GetKind())] = ob + } + } + return binaryKeyValues, nil +} + +func getRegistryConfigMapName(pkgName string) string { + name := k8sutil.FormatOperatorNameDNS1123(pkgName) + return fmt.Sprintf("%s-registry-bundles", name) +} + +// withBinaryData returns a function that creates entries in the ConfigMap +// argument's binaryData for each key and []byte value in kvs. +func withBinaryData(kvs map[string][]byte) func(*corev1.ConfigMap) { + return func(cm *corev1.ConfigMap) { + if cm.BinaryData == nil { + cm.BinaryData = map[string][]byte{} + } + for k, v := range kvs { + cm.BinaryData[k] = v + } + } +} + +// newRegistryConfigMap creates a new ConfigMap with a name derived from +// pkgName, the package manifest's packageName, in namespace. opts will +// be applied to the ConfigMap object. +func newRegistryConfigMap(pkgName, namespace string, opts ...func(*corev1.ConfigMap)) *corev1.ConfigMap { + cm := &corev1.ConfigMap{ + TypeMeta: metav1.TypeMeta{ + APIVersion: corev1.SchemeGroupVersion.String(), + Kind: "ConfigMap", + }, + ObjectMeta: metav1.ObjectMeta{ + Name: getRegistryConfigMapName(pkgName), + Namespace: namespace, + }, + } + for _, opt := range opts { + opt(cm) + } + return cm +} diff --git a/internal/olm/operator/internal/deployment.go b/internal/olm/operator/internal/deployment.go new file mode 100644 index 00000000000..639e2ae0ed0 --- /dev/null +++ b/internal/olm/operator/internal/deployment.go @@ -0,0 +1,176 @@ +// Copyright 2019 The Operator-SDK Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package olm + +import ( + "fmt" + + "github.com/operator-framework/operator-sdk/internal/util/k8sutil" + + appsv1 "k8s.io/api/apps/v1" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +const ( + // The image operator-registry's initializer and registry-server binaries + // are run from. + // QUESTION(estroz): version registry image? + registryBaseImage = "quay.io/openshift/origin-operator-registry:latest" + // The port registry-server will listen on within a container. + registryGRPCPort = 50051 + // Path of the bundle database generated by initializer. + regisryDBName = "bundle.db" + // Path of the log file generated by registry-server. + // TODO(estroz): have this log file in an obvious place, ex. /var/log. + registryLogFile = "termination.log" +) + +func getRegistryServerName(pkgName string) string { + name := k8sutil.FormatOperatorNameDNS1123(pkgName) + return fmt.Sprintf("%s-registry-server", name) +} + +func getRegistryVolumeName(pkgName string) string { + name := k8sutil.FormatOperatorNameDNS1123(pkgName) + return fmt.Sprintf("%s-bundle-db", name) +} + +// getRegistryDeploymentLabels creates a set of labels to identify +// operator-registry Deployment objects. +func getRegistryDeploymentLabels(pkgName string) map[string]string { + labels := map[string]string{ + "name": getRegistryServerName(pkgName), + } + for k, v := range SDKLabels { + labels[k] = v + } + return labels +} + +// applyToDeploymentPodSpec applies f to dep's pod template spec. +func applyToDeploymentPodSpec(dep *appsv1.Deployment, f func(*corev1.PodSpec)) { + f(&dep.Spec.Template.Spec) +} + +// withVolumeConfigMap returns a function that appends a volume with name +// volName containing a reference to a ConfigMap with name cmName to the +// Deployment argument's pod template spec. +func withVolumeConfigMap(volName, cmName string) func(*appsv1.Deployment) { + volume := corev1.Volume{ + Name: volName, + VolumeSource: corev1.VolumeSource{ + ConfigMap: &corev1.ConfigMapVolumeSource{ + LocalObjectReference: corev1.LocalObjectReference{ + Name: cmName, + }, + }, + }, + } + return func(dep *appsv1.Deployment) { + applyToDeploymentPodSpec(dep, func(spec *corev1.PodSpec) { + spec.Volumes = append(spec.Volumes, volume) + }) + } +} + +// withContainerVolumeMounts returns a function that appends volumeMounts +// to each container in the Deployment argument's pod template spec. One +// volumeMount is appended for each path in paths from volume with name +// volName. +func withContainerVolumeMounts(volName string, paths []string) func(*appsv1.Deployment) { + volumeMounts := []corev1.VolumeMount{} + for _, p := range paths { + volumeMounts = append(volumeMounts, corev1.VolumeMount{ + Name: volName, + MountPath: p, + }) + } + return func(dep *appsv1.Deployment) { + applyToDeploymentPodSpec(dep, func(spec *corev1.PodSpec) { + for i := range spec.Containers { + spec.Containers[i].VolumeMounts = append(spec.Containers[i].VolumeMounts, volumeMounts...) + } + }) + } +} + +// getDBContainerCmd returns a command string that, when run, does two things: +// 1. Runs a database initializer on the manifests in the current working +// directory. +// 2. Runs an operator-registry server serving the bundle database. +// The database must be in the current working directory. +func getDBContainerCmd(dbPath, logPath string) string { + initCmd := fmt.Sprintf("/usr/bin/initializer -o %s", dbPath) + srvCmd := fmt.Sprintf("/usr/bin/registry-server -d %s -t %s", dbPath, logPath) + return fmt.Sprintf("%s && %s", initCmd, srvCmd) +} + +// withRegistryGRPCContainer returns a function that appends a container +// running an operator-registry GRPC server to the Deployment argument's +// pod template spec. +func withRegistryGRPCContainer(pkgName string) func(*appsv1.Deployment) { + container := corev1.Container{ + Name: getRegistryServerName(pkgName), + Image: registryBaseImage, + Command: []string{"/bin/bash"}, + Args: []string{ + "-c", + // TODO(estroz): grab logs and print if error + getDBContainerCmd(regisryDBName, registryLogFile), + }, + Ports: []corev1.ContainerPort{ + {Name: "registry-grpc", ContainerPort: registryGRPCPort}, + }, + } + return func(dep *appsv1.Deployment) { + applyToDeploymentPodSpec(dep, func(spec *corev1.PodSpec) { + spec.Containers = append(spec.Containers, container) + }) + } +} + +// newRegistryDeployment creates a new Deployment with a name derived from +// pkgName, the package manifest's packageName, in namespace. The Deployment +// and replicas are created with labels derived from pkgName. opts will be +// applied to the Deployment object. +func newRegistryDeployment(pkgName, namespace string, opts ...func(*appsv1.Deployment)) *appsv1.Deployment { + var replicas int32 = 1 + dep := &appsv1.Deployment{ + TypeMeta: metav1.TypeMeta{ + APIVersion: appsv1.SchemeGroupVersion.String(), + Kind: "Deployment", + }, + ObjectMeta: metav1.ObjectMeta{ + Name: getRegistryServerName(pkgName), + Namespace: namespace, + }, + Spec: appsv1.DeploymentSpec{ + Selector: &metav1.LabelSelector{ + MatchLabels: getRegistryDeploymentLabels(pkgName), + }, + Replicas: &replicas, + Template: corev1.PodTemplateSpec{ + ObjectMeta: metav1.ObjectMeta{ + Labels: getRegistryDeploymentLabels(pkgName), + }, + }, + }, + } + for _, opt := range opts { + opt(dep) + } + return dep +} diff --git a/internal/olm/operator/internal/registry.go b/internal/olm/operator/internal/registry.go new file mode 100644 index 00000000000..80a3eb40120 --- /dev/null +++ b/internal/olm/operator/internal/registry.go @@ -0,0 +1,98 @@ +// Copyright 2019 The Operator-SDK Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package olm + +import ( + "context" + "fmt" + + olmresourceclient "github.com/operator-framework/operator-sdk/internal/olm/client" + registryutil "github.com/operator-framework/operator-sdk/internal/util/operator-registry" + + "github.com/pkg/errors" + log "github.com/sirupsen/logrus" + "k8s.io/apimachinery/pkg/types" +) + +// SDKLabels are used to identify certain operator-sdk resources. +var SDKLabels = map[string]string{ + "owner": "operator-sdk", +} + +// RegistryResources configures creation/deletion of internal registry-related +// resources. +type RegistryResources struct { + Client *olmresourceclient.Client + Manifests registryutil.ManifestsStore +} + +// FEAT(estroz): allow users to specify labels for registry objects. + +// CreateRegistryManifests creates all registry objects required to serve +// manifests from m.manifests in namespace. +func (m *RegistryResources) CreateRegistryManifests(ctx context.Context, namespace string) error { + pkg := m.Manifests.GetPackageManifest() + pkgName := pkg.PackageName + bundles := m.Manifests.GetBundles() + binaryKeyValues, err := createConfigMapBinaryData(pkg, bundles) + if err != nil { + return errors.Wrap(err, "error creating registry ConfigMap binary data") + } + cm := newRegistryConfigMap(pkgName, namespace, + withBinaryData(binaryKeyValues), + ) + volName := getRegistryVolumeName(pkgName) + dep := newRegistryDeployment(pkgName, namespace, + withRegistryGRPCContainer(pkgName), + withVolumeConfigMap(volName, cm.GetName()), + withContainerVolumeMounts(volName, []string{containerManifestsDir}), + ) + service := newRegistryService(pkgName, namespace, + withTCPPort("grpc", registryGRPCPort), + ) + if err = m.Client.DoCreate(ctx, cm, dep, service); err != nil { + return errors.Wrapf(err, "error creating operator %q registry-server objects", pkgName) + } + depKey := types.NamespacedName{ + Name: dep.GetName(), + Namespace: namespace, + } + log.Infof("Waiting for Deployment %q rollout to complete", depKey) + if err = m.Client.DoRolloutWait(ctx, depKey); err != nil { + return errors.Wrapf(err, "error waiting for Deployment %q to roll out", depKey) + } + return nil +} + +// DeleteRegistryManifests deletes all registry objects serving manifests +// from m.manifests in namespace. +func (m *RegistryResources) DeleteRegistryManifests(ctx context.Context, namespace string) error { + pkgName := m.Manifests.GetPackageManifest().PackageName + cm := newRegistryConfigMap(pkgName, namespace) + dep := newRegistryDeployment(pkgName, namespace) + service := newRegistryService(pkgName, namespace) + err := m.Client.DoDelete(ctx, dep, cm, service) + if err != nil { + return errors.Wrapf(err, "error deleting operator %q registry-server objects", pkgName) + } + return nil +} + +// GetRegistryServiceAddr returns a Service's DNS name + port for a given +// pkgName and namespace. +func GetRegistryServiceAddr(pkgName, namespace string) string { + name := getRegistryServerName(pkgName) + return fmt.Sprintf("%s.%s.svc.cluster.local:%d", name, namespace, registryGRPCPort) +} diff --git a/internal/olm/operator/internal/service.go b/internal/olm/operator/internal/service.go new file mode 100644 index 00000000000..064815a2f3d --- /dev/null +++ b/internal/olm/operator/internal/service.go @@ -0,0 +1,57 @@ +// Copyright 2019 The Operator-SDK Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package olm + +import ( + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/intstr" +) + +// withTCPPort returns a function that appends a service port to a Service's +// port list with name and TCP port portNum. +func withTCPPort(name string, portNum int32) func(*corev1.Service) { + return func(service *corev1.Service) { + service.Spec.Ports = append(service.Spec.Ports, corev1.ServicePort{ + Name: name, + Protocol: corev1.ProtocolTCP, + Port: portNum, + TargetPort: intstr.FromInt(int(portNum)), + }) + } +} + +// newRegistryService creates a new Service with a name derived from pkgName +// the package manifest's packageName, in namespace. The Service is created +// with labels derived from pkgName. opts will be applied to the Service object. +func newRegistryService(pkgName, namespace string, opts ...func(*corev1.Service)) *corev1.Service { + service := &corev1.Service{ + TypeMeta: metav1.TypeMeta{ + APIVersion: corev1.SchemeGroupVersion.String(), + Kind: "Service", + }, + ObjectMeta: metav1.ObjectMeta{ + Name: getRegistryServerName(pkgName), + Namespace: namespace, + }, + Spec: corev1.ServiceSpec{ + Selector: getRegistryDeploymentLabels(pkgName), + }, + } + for _, opt := range opts { + opt(service) + } + return service +} From 68e322d5d41c616710b48e2bac6cd8109d747380 Mon Sep 17 00:00:00 2001 From: Eric Stroczynski Date: Wed, 11 Dec 2019 08:49:50 -0800 Subject: [PATCH 2/6] use PackageManifest and Bundle types directly --- go.mod | 4 +++- go.sum | 15 ++++++++++++ internal/olm/operator/internal/configmap.go | 5 ++-- internal/olm/operator/internal/registry.go | 26 ++++++++++----------- internal/util/k8sutil/k8sutil.go | 14 +++++++++++ 5 files changed, 46 insertions(+), 18 deletions(-) diff --git a/go.mod b/go.mod index 37ca8152b03..c1074b046a6 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,9 @@ require ( github.com/go-logr/zapr v0.1.1 github.com/gobuffalo/packr v1.30.1 // indirect github.com/gobwas/glob v0.2.3 // indirect + github.com/golang/groupcache v0.0.0-20191027212112-611e8accdfc9 // indirect github.com/gregjones/httpcache v0.0.0-20190203031600-7a902570cb17 // indirect + github.com/hashicorp/golang-lru v0.5.3 // indirect github.com/huandu/xstrings v1.2.0 // indirect github.com/iancoleman/strcase v0.0.0-20190422225806-e506e3ef7365 github.com/jmoiron/sqlx v1.2.0 // indirect @@ -29,7 +31,7 @@ require ( github.com/mitchellh/go-homedir v1.1.0 github.com/mitchellh/mapstructure v1.1.2 github.com/operator-framework/operator-lifecycle-manager v0.0.0-20191115003340-16619cd27fa5 - github.com/operator-framework/operator-registry v1.5.1 + github.com/operator-framework/operator-registry v1.5.3 github.com/pborman/uuid v1.2.0 github.com/pkg/errors v0.8.1 github.com/prometheus/client_golang v1.1.0 diff --git a/go.sum b/go.sum index 6058ba532b0..86c6630ab56 100644 --- a/go.sum +++ b/go.sum @@ -64,6 +64,7 @@ github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY= +github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a h1:idn718Q4B6AGu/h5Sxe66HYVdqdGu2l9Iebqhi/AEoA= github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY= github.com/auth0/go-jwt-middleware v0.0.0-20170425171159-5493cabe49f7/go.mod h1:LWMyo4iOLWXHGdBki7NIht1kHru/0wM179h+d3g8ATM= github.com/aws/aws-sdk-go v1.16.26/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= @@ -200,6 +201,7 @@ github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeME github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32 h1:Mn26/9ZMNWSw9C9ERFA1PUxfmGpolnw2v0bKOREu5ew= github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32/go.mod h1:GIjDIg/heH5DOkXY3YJ/wNhfHsQHoXGjl8G8amsYQ1I= github.com/globalsign/mgo v0.0.0-20180905125535-1ca0a4f7cbcb/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q= +github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8 h1:DujepqpGd1hyOd7aW59XpK7Qymp8iy83xq74fLr21is= github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q= github.com/go-acme/lego v2.5.0+incompatible/go.mod h1:yzMNe9CasVUhkquNvti5nAtPmG94USbYxYrZfTkIn0M= github.com/go-bindata/go-bindata v3.1.1+incompatible/go.mod h1:xK8Dsgwmeed+BBsSy2XTopBn/8uK2HWuGSnA11C3Joo= @@ -215,9 +217,11 @@ github.com/go-logr/zapr v0.1.1/go.mod h1:tabnROwaDl0UNxkVeFRbY8bwB37GwRv0P8lg6aA github.com/go-openapi/analysis v0.0.0-20180825180245-b006789cd277/go.mod h1:k70tL6pCuVxPJOHXQ+wIac1FUrvNkHolPie/cLEU6hI= github.com/go-openapi/analysis v0.17.0/go.mod h1:IowGgpVeD0vNm45So8nr+IcQ3pxVtpRoBWb8PVZO0ik= github.com/go-openapi/analysis v0.18.0/go.mod h1:IowGgpVeD0vNm45So8nr+IcQ3pxVtpRoBWb8PVZO0ik= +github.com/go-openapi/analysis v0.19.2 h1:ophLETFestFZHk3ji7niPEL4d466QjW+0Tdg5VyDq7E= github.com/go-openapi/analysis v0.19.2/go.mod h1:3P1osvZa9jKjb8ed2TPng3f0i/UY9snX6gxi44djMjk= github.com/go-openapi/errors v0.17.0/go.mod h1:LcZQpmvG4wyF5j4IhA73wkLFQg+QJXOQHVjmcZxhka0= github.com/go-openapi/errors v0.18.0/go.mod h1:LcZQpmvG4wyF5j4IhA73wkLFQg+QJXOQHVjmcZxhka0= +github.com/go-openapi/errors v0.19.2 h1:a2kIyV3w+OS3S97zxUndRVD46+FhGOUBDFY7nmu4CsY= github.com/go-openapi/errors v0.19.2/go.mod h1:qX0BLWsyaKfvhluLejVpVNwNRdXZhEbTA4kxxpKBC94= github.com/go-openapi/jsonpointer v0.0.0-20160704185906-46af16f9f7b1/go.mod h1:+35s3my2LFTysnkMfxsJBAMHj/DoqoB9knIWoYG/Vk0= github.com/go-openapi/jsonpointer v0.17.0/go.mod h1:cOnomiV+CVVwFLk0A/MExoFMjwdsUdVpsRhURCKh+3M= @@ -232,8 +236,10 @@ github.com/go-openapi/jsonreference v0.19.2/go.mod h1:jMjeRr2HHw6nAVajTXJ4eiUwoh github.com/go-openapi/loads v0.17.0/go.mod h1:72tmFy5wsWx89uEVddd0RjRWPZm92WRLhf7AC+0+OOU= github.com/go-openapi/loads v0.18.0/go.mod h1:72tmFy5wsWx89uEVddd0RjRWPZm92WRLhf7AC+0+OOU= github.com/go-openapi/loads v0.19.0/go.mod h1:72tmFy5wsWx89uEVddd0RjRWPZm92WRLhf7AC+0+OOU= +github.com/go-openapi/loads v0.19.2 h1:rf5ArTHmIJxyV5Oiks+Su0mUens1+AjpkPoWr5xFRcI= github.com/go-openapi/loads v0.19.2/go.mod h1:QAskZPMX5V0C2gvfkGZzJlINuP7Hx/4+ix5jWFxsNPs= github.com/go-openapi/runtime v0.0.0-20180920151709-4f900dc2ade9/go.mod h1:6v9a6LTXWQCdL8k1AO3cvqx5OtZY/Y9wKTgaoP6YRfA= +github.com/go-openapi/runtime v0.19.0 h1:sU6pp4dSV2sGlNKKyHxZzi1m1kG4WnYtWcJ+HYbygjE= github.com/go-openapi/runtime v0.19.0/go.mod h1:OwNfisksmmaZse4+gpV3Ne9AyMOlP1lt4sK4FXt0O64= github.com/go-openapi/spec v0.0.0-20160808142527-6aced65f8501/go.mod h1:J8+jY1nAiCcj+friV/PDoE1/3eeccG9LYBs0tYvLOWc= github.com/go-openapi/spec v0.17.0/go.mod h1:XkF/MOi14NmjsfZ8VtAKf8pIlbZzyoTvZsdfssdxcBI= @@ -242,6 +248,7 @@ github.com/go-openapi/spec v0.19.2 h1:SStNd1jRcYtfKCN7R0laGNs80WYYvn5CbBjM2sOmCr github.com/go-openapi/spec v0.19.2/go.mod h1:sCxk3jxKgioEJikev4fgkNmwS+3kuYdJtcsZsD5zxMY= github.com/go-openapi/strfmt v0.17.0/go.mod h1:P82hnJI0CXkErkXi8IKjPbNBM6lV6+5pLP5l494TcyU= github.com/go-openapi/strfmt v0.18.0/go.mod h1:P82hnJI0CXkErkXi8IKjPbNBM6lV6+5pLP5l494TcyU= +github.com/go-openapi/strfmt v0.19.0 h1:0Dn9qy1G9+UJfRU7TR8bmdGxb4uifB7HNrJjOnV0yPk= github.com/go-openapi/strfmt v0.19.0/go.mod h1:+uW+93UVvGGq2qGaZxdDeJqSAqBqBdl+ZPMF/cC8nDY= github.com/go-openapi/swag v0.0.0-20160704191624-1d0bd113de87/go.mod h1:DXUve3Dpr1UfpPtxFw+EFuQ41HhCWZfha5jSVRG7C7I= github.com/go-openapi/swag v0.17.0/go.mod h1:AByQ+nYG6gQg71GINrmuDXCPWdL640yX49/kXLo40Tg= @@ -251,6 +258,7 @@ github.com/go-openapi/swag v0.19.2/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh github.com/go-openapi/swag v0.19.4 h1:i/65mCM9s1h8eCkT07F5Z/C1e/f8VTgEwer+00yevpA= github.com/go-openapi/swag v0.19.4/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= github.com/go-openapi/validate v0.18.0/go.mod h1:Uh4HdOzKt19xGIGm1qHf/ofbX1YQ4Y+MYsct2VUrAJ4= +github.com/go-openapi/validate v0.19.2 h1:ky5l57HjyVRrsJfd2+Ro5Z9PjGuKbsmftwyMtk8H7js= github.com/go-openapi/validate v0.19.2/go.mod h1:1tRCw7m3jtI8eNWEEliiAqUIcBztB2KDnRCRMUi7GTA= github.com/go-ozzo/ozzo-validation v3.5.0+incompatible/go.mod h1:gsEKFIVnabGBt6mXmxK0MoFy+cZoTJY6mu5Ll3LVLBU= github.com/go-sql-driver/mysql v1.4.0 h1:7LxgVwFb2hIQtMm87NdgAVfXjnt4OePseqT1tKx+opk= @@ -280,6 +288,7 @@ github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d h1:3PaI8p3seN09Vjb github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= github.com/gogo/protobuf v1.2.2-0.20190730201129-28a6bbf47e48 h1:X+zN6RZXsvnrSJaAIQhZezPfAfvsqihKKR8oiLHid34= github.com/gogo/protobuf v1.2.2-0.20190730201129-28a6bbf47e48/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= +github.com/golang-migrate/migrate/v4 v4.6.2 h1:LDDOHo/q1W5UDj6PbkxdCv7lv9yunyZHXvxuwDkGo3k= github.com/golang-migrate/migrate/v4 v4.6.2/go.mod h1:JYi6reN3+Z734VZ0akNuyOJNcrg45ZL7LDBMW3WGJL0= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= @@ -288,6 +297,8 @@ github.com/golang/groupcache v0.0.0-20180513044358-24b0969c4cb7/go.mod h1:cIg4er github.com/golang/groupcache v0.0.0-20181024230925-c65c006176ff/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef h1:veQD95Isof8w9/WXiA+pa3tz3fJXkt5B7QaRBrM62gk= github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20191027212112-611e8accdfc9 h1:uHTyIjqVhYRhLbJ8nIiOJHkEZZ+5YoOsAbD3sk82NiE= +github.com/golang/groupcache v0.0.0-20191027212112-611e8accdfc9/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.3.1 h1:qGJ6qTW+x6xX/my+8YUVl4WNpX9B7+/l2tRsHGZ7f2s= @@ -364,6 +375,8 @@ github.com/hashicorp/golang-lru v0.0.0-20180201235237-0fb14efe8c47/go.mod h1:/m3 github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1 h1:0hERBMJE1eitiLkihrMvRVBYAkpHzc/J3QdDN+dAcgU= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/golang-lru v0.5.3 h1:YPkqC67at8FYaadspW/6uE0COsBxS2656RLEr8Bppgk= +github.com/hashicorp/golang-lru v0.5.3/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/heketi/heketi v9.0.0+incompatible/go.mod h1:bB9ly3RchcQqsQ9CpyaQwvva7RS5ytVoSoholZQON6o= @@ -527,6 +540,8 @@ github.com/operator-framework/operator-lifecycle-manager v0.0.0-20191115003340-1 github.com/operator-framework/operator-lifecycle-manager v0.0.0-20191115003340-16619cd27fa5/go.mod h1:zL34MNy92LPutBH5gQK+gGhtgTUlZZX03I2G12vWHF4= github.com/operator-framework/operator-registry v1.5.1 h1:8ruUOG6IBDVTAXYWKsv6hwr4yv/0SFPFPAYGCpcv97E= github.com/operator-framework/operator-registry v1.5.1/go.mod h1:agrQlkWOo1q8U1SAaLSS2WQ+Z9vswNT2M2HFib9iuLY= +github.com/operator-framework/operator-registry v1.5.3 h1:az83WDwgB+tHsmVn+tFq72yQBbaUAye8e4+KkDQmzLs= +github.com/operator-framework/operator-registry v1.5.3/go.mod h1:agrQlkWOo1q8U1SAaLSS2WQ+Z9vswNT2M2HFib9iuLY= github.com/otiai10/copy v1.0.1/go.mod h1:8bMCJrAqOtN/d9oyh5HR7HhLQMvcGMpGdwRDYsfOCHc= github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE= github.com/otiai10/curr v0.0.0-20190513014714-f5a3d24e5776/go.mod h1:3HNVkVOU7vZeFXocWuvtcS0XSFLcf2XUSDHkq9t1jU4= diff --git a/internal/olm/operator/internal/configmap.go b/internal/olm/operator/internal/configmap.go index dedd304c213..a9e0e0cb7b9 100644 --- a/internal/olm/operator/internal/configmap.go +++ b/internal/olm/operator/internal/configmap.go @@ -40,8 +40,7 @@ const ( // IsManifestDataStale checks if manifest data stored in the registry is stale // by comparing it to manifest data currently managed by m. func (m *RegistryResources) IsManifestDataStale(ctx context.Context, namespace string) (bool, error) { - pkg := m.Manifests.GetPackageManifest() - pkgName := pkg.PackageName + pkgName := m.Pkg.PackageName nn := types.NamespacedName{ Name: getRegistryConfigMapName(pkgName), Namespace: namespace, @@ -52,7 +51,7 @@ func (m *RegistryResources) IsManifestDataStale(ctx context.Context, namespace s return false, err } // Collect digests of manifests submitted to m. - newData, err := createConfigMapBinaryData(pkg, m.Manifests.GetBundles()) + newData, err := createConfigMapBinaryData(m.Pkg, m.Bundles) if err != nil { return false, errors.Wrap(err, "error creating binary data") } diff --git a/internal/olm/operator/internal/registry.go b/internal/olm/operator/internal/registry.go index 80a3eb40120..135b108dd26 100644 --- a/internal/olm/operator/internal/registry.go +++ b/internal/olm/operator/internal/registry.go @@ -18,10 +18,9 @@ import ( "context" "fmt" - olmresourceclient "github.com/operator-framework/operator-sdk/internal/olm/client" - registryutil "github.com/operator-framework/operator-sdk/internal/util/operator-registry" + olmclient "github.com/operator-framework/operator-sdk/internal/olm/client" - "github.com/pkg/errors" + "github.com/operator-framework/operator-registry/pkg/registry" log "github.com/sirupsen/logrus" "k8s.io/apimachinery/pkg/types" ) @@ -34,8 +33,9 @@ var SDKLabels = map[string]string{ // RegistryResources configures creation/deletion of internal registry-related // resources. type RegistryResources struct { - Client *olmresourceclient.Client - Manifests registryutil.ManifestsStore + Client *olmclient.Client + Pkg registry.PackageManifest + Bundles []*registry.Bundle } // FEAT(estroz): allow users to specify labels for registry objects. @@ -43,12 +43,10 @@ type RegistryResources struct { // CreateRegistryManifests creates all registry objects required to serve // manifests from m.manifests in namespace. func (m *RegistryResources) CreateRegistryManifests(ctx context.Context, namespace string) error { - pkg := m.Manifests.GetPackageManifest() - pkgName := pkg.PackageName - bundles := m.Manifests.GetBundles() - binaryKeyValues, err := createConfigMapBinaryData(pkg, bundles) + pkgName := m.Pkg.PackageName + binaryKeyValues, err := createConfigMapBinaryData(m.Pkg, m.Bundles) if err != nil { - return errors.Wrap(err, "error creating registry ConfigMap binary data") + return fmt.Errorf("error creating registry ConfigMap binary data: %w", err) } cm := newRegistryConfigMap(pkgName, namespace, withBinaryData(binaryKeyValues), @@ -63,7 +61,7 @@ func (m *RegistryResources) CreateRegistryManifests(ctx context.Context, namespa withTCPPort("grpc", registryGRPCPort), ) if err = m.Client.DoCreate(ctx, cm, dep, service); err != nil { - return errors.Wrapf(err, "error creating operator %q registry-server objects", pkgName) + return fmt.Errorf("error creating operator %q registry-server objects: %w", pkgName, err) } depKey := types.NamespacedName{ Name: dep.GetName(), @@ -71,7 +69,7 @@ func (m *RegistryResources) CreateRegistryManifests(ctx context.Context, namespa } log.Infof("Waiting for Deployment %q rollout to complete", depKey) if err = m.Client.DoRolloutWait(ctx, depKey); err != nil { - return errors.Wrapf(err, "error waiting for Deployment %q to roll out", depKey) + return fmt.Errorf("error waiting for Deployment %q to roll out: %w", depKey, err) } return nil } @@ -79,13 +77,13 @@ func (m *RegistryResources) CreateRegistryManifests(ctx context.Context, namespa // DeleteRegistryManifests deletes all registry objects serving manifests // from m.manifests in namespace. func (m *RegistryResources) DeleteRegistryManifests(ctx context.Context, namespace string) error { - pkgName := m.Manifests.GetPackageManifest().PackageName + pkgName := m.Pkg.PackageName cm := newRegistryConfigMap(pkgName, namespace) dep := newRegistryDeployment(pkgName, namespace) service := newRegistryService(pkgName, namespace) err := m.Client.DoDelete(ctx, dep, cm, service) if err != nil { - return errors.Wrapf(err, "error deleting operator %q registry-server objects", pkgName) + return fmt.Errorf("error deleting operator %q registry-server objects: %w", pkgName, err) } return nil } diff --git a/internal/util/k8sutil/k8sutil.go b/internal/util/k8sutil/k8sutil.go index bb934a29e5b..48ea5bcbd3f 100644 --- a/internal/util/k8sutil/k8sutil.go +++ b/internal/util/k8sutil/k8sutil.go @@ -18,12 +18,14 @@ import ( "bytes" "fmt" "io" + "regexp" "strings" "unicode" "github.com/pkg/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + "k8s.io/apimachinery/pkg/util/validation" "k8s.io/apimachinery/pkg/util/yaml" "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" @@ -113,3 +115,15 @@ func GetTypeMetaFromBytes(b []byte) (t metav1.TypeMeta, err error) { Kind: u.GetKind(), }, nil } + +// dns1123LabelRegexp defines the character set allowed in a DNS 1123 label. +var dns1123LabelRegexp = regexp.MustCompile("[^a-zA-Z0-9]+") + +// FormatOperatorNameDNS1123 ensures name is DNS1123 label-compliant by +// replacing all non-compliant UTF-8 characters with "-". +func FormatOperatorNameDNS1123(name string) string { + if len(validation.IsDNS1123Label(name)) != 0 { + return dns1123LabelRegexp.ReplaceAllString(name, "-") + } + return name +} From f049b3d78d8a987d0c39409fe2ba8f0d94962698 Mon Sep 17 00:00:00 2001 From: Eric Stroczynski Date: Wed, 11 Dec 2019 08:51:13 -0800 Subject: [PATCH 3/6] test/test-framework: revendor --- test/test-framework/go.sum | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/test-framework/go.sum b/test/test-framework/go.sum index 4e300b8e33b..c878373c4a1 100644 --- a/test/test-framework/go.sum +++ b/test/test-framework/go.sum @@ -251,6 +251,8 @@ github.com/golang/groupcache v0.0.0-20180513044358-24b0969c4cb7/go.mod h1:cIg4er github.com/golang/groupcache v0.0.0-20181024230925-c65c006176ff/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef h1:veQD95Isof8w9/WXiA+pa3tz3fJXkt5B7QaRBrM62gk= github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20191027212112-611e8accdfc9 h1:uHTyIjqVhYRhLbJ8nIiOJHkEZZ+5YoOsAbD3sk82NiE= +github.com/golang/groupcache v0.0.0-20191027212112-611e8accdfc9/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= @@ -320,6 +322,8 @@ github.com/hashicorp/golang-lru v0.5.0 h1:CL2msUPvZTLb5O648aiLNJw3hnBxN2+1Jq8rCO github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1 h1:0hERBMJE1eitiLkihrMvRVBYAkpHzc/J3QdDN+dAcgU= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/golang-lru v0.5.3 h1:YPkqC67at8FYaadspW/6uE0COsBxS2656RLEr8Bppgk= +github.com/hashicorp/golang-lru v0.5.3/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/heketi/heketi v9.0.0+incompatible/go.mod h1:bB9ly3RchcQqsQ9CpyaQwvva7RS5ytVoSoholZQON6o= github.com/heketi/rest v0.0.0-20180404230133-aa6a65207413/go.mod h1:BeS3M108VzVlmAue3lv2WcGuPAX94/KN63MUURzbYSI= @@ -463,6 +467,7 @@ github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFSt github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw= github.com/operator-framework/operator-lifecycle-manager v0.0.0-20191115003340-16619cd27fa5/go.mod h1:zL34MNy92LPutBH5gQK+gGhtgTUlZZX03I2G12vWHF4= github.com/operator-framework/operator-registry v1.5.1/go.mod h1:agrQlkWOo1q8U1SAaLSS2WQ+Z9vswNT2M2HFib9iuLY= +github.com/operator-framework/operator-registry v1.5.3/go.mod h1:agrQlkWOo1q8U1SAaLSS2WQ+Z9vswNT2M2HFib9iuLY= github.com/otiai10/copy v1.0.1/go.mod h1:8bMCJrAqOtN/d9oyh5HR7HhLQMvcGMpGdwRDYsfOCHc= github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE= github.com/otiai10/curr v0.0.0-20190513014714-f5a3d24e5776/go.mod h1:3HNVkVOU7vZeFXocWuvtcS0XSFLcf2XUSDHkq9t1jU4= From bc08d4e2643755c1f1192bac8d564da15d7c723f Mon Sep 17 00:00:00 2001 From: Eric Stroczynski Date: Wed, 11 Dec 2019 08:58:40 -0800 Subject: [PATCH 4/6] use getObjectFileName in getPackageFileName --- internal/olm/operator/internal/configmap.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/internal/olm/operator/internal/configmap.go b/internal/olm/operator/internal/configmap.go index a9e0e0cb7b9..0528b3fa0e7 100644 --- a/internal/olm/operator/internal/configmap.go +++ b/internal/olm/operator/internal/configmap.go @@ -85,8 +85,7 @@ func getObjectFileName(b []byte, name, kind string) string { } func getPackageFileName(b []byte, name string) string { - digest := hashContents(b) - return fmt.Sprintf("%s.%s.package.yaml", digest, name) + return getObjectFileName(b, name, "package") } // createConfigMapBinaryData opaquely creates a set of paths using data in pkg From 2d03ce3e598da361a5aac6a97d31319a7f986ab6 Mon Sep 17 00:00:00 2001 From: Eric Stroczynski Date: Wed, 11 Dec 2019 09:02:47 -0800 Subject: [PATCH 5/6] use fmt.Errorf over errors.Wrap --- internal/olm/operator/internal/configmap.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/internal/olm/operator/internal/configmap.go b/internal/olm/operator/internal/configmap.go index 0528b3fa0e7..77903a76545 100644 --- a/internal/olm/operator/internal/configmap.go +++ b/internal/olm/operator/internal/configmap.go @@ -25,7 +25,6 @@ import ( "github.com/ghodss/yaml" "github.com/operator-framework/operator-registry/pkg/registry" - "github.com/pkg/errors" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" @@ -53,7 +52,7 @@ func (m *RegistryResources) IsManifestDataStale(ctx context.Context, namespace s // Collect digests of manifests submitted to m. newData, err := createConfigMapBinaryData(m.Pkg, m.Bundles) if err != nil { - return false, errors.Wrap(err, "error creating binary data") + return false, fmt.Errorf("error creating binary data: %w", err) } // If the number of files to be added to the registry don't match the number // of files currently in the registry, we have added or removed a file. @@ -96,14 +95,14 @@ func createConfigMapBinaryData(pkg registry.PackageManifest, bundles []*registry binaryKeyValues := map[string][]byte{} pb, err := yaml.Marshal(pkg) if err != nil { - return nil, errors.Wrapf(err, "error marshalling package manifest %s", pkgName) + return nil, fmt.Errorf("error marshalling package manifest %s: %w", pkgName, err) } binaryKeyValues[getPackageFileName(pb, pkgName)] = pb for _, bundle := range bundles { for _, o := range bundle.Objects { ob, err := yaml.Marshal(o) if err != nil { - return nil, errors.Wrapf(err, "error marshalling object %s %q", o.GroupVersionKind(), o.GetName()) + return nil, fmt.Errorf("error marshalling object %s %q: %w", o.GroupVersionKind(), o.GetName(), err) } binaryKeyValues[getObjectFileName(ob, o.GetName(), o.GetKind())] = ob } From 8601769466526e4e74f95f904833086780e2b720 Mon Sep 17 00:00:00 2001 From: Eric Stroczynski Date: Tue, 7 Jan 2020 16:38:14 -0800 Subject: [PATCH 6/6] remove go.sum duplicate entry --- go.sum | 1 - 1 file changed, 1 deletion(-) diff --git a/go.sum b/go.sum index 54215a1950a..5ee1b28e10b 100644 --- a/go.sum +++ b/go.sum @@ -327,7 +327,6 @@ github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7a github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= github.com/gogo/protobuf v1.2.2-0.20190730201129-28a6bbf47e48/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= -github.com/golang-migrate/migrate/v4 v4.6.2 h1:LDDOHo/q1W5UDj6PbkxdCv7lv9yunyZHXvxuwDkGo3k= github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls= github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= github.com/golang-migrate/migrate/v4 v4.6.2 h1:LDDOHo/q1W5UDj6PbkxdCv7lv9yunyZHXvxuwDkGo3k=