Skip to content

Commit

Permalink
Fix lint
Browse files Browse the repository at this point in the history
Signed-off-by: Andy Goldstein <andy.goldstein@redhat.com>
  • Loading branch information
ncdc committed Jan 11, 2024
1 parent 0d2d9b7 commit c504538
Show file tree
Hide file tree
Showing 34 changed files with 291 additions and 282 deletions.
1 change: 0 additions & 1 deletion hack/generate/samples/generate_testdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,4 @@ func main() {

log.Infof("creating Hybrid Memcached Sample")
hybrid.GenerateMemcachedSamples(binaryPath, samplesPath)

}
4 changes: 3 additions & 1 deletion hack/generate/samples/internal/pkg/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ type SampleContext struct {
}

// NewSampleContext returns a SampleContext containing a new kubebuilder TestContext.
func NewSampleContext(binary string, path string, env ...string) (s SampleContext, err error) {
func NewSampleContext(binary string, path string, env ...string) (SampleContext, error) {
var s SampleContext
var err error
s.TestContext, err = testutils.NewPartialTestContext(binary, path, env...)
return s, err
}
1 change: 0 additions & 1 deletion internal/cmd/helm-operator/run/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ func run(cmd *cobra.Command, f *flags.Flags) {
log.Error(err, "Manager exited non-zero.")
os.Exit(1)
}

}

// exitIfUnsupported prints an error containing unsupported field names and exits
Expand Down
1 change: 0 additions & 1 deletion internal/flags/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ func (f *Flags) AddTo(flagSet *pflag.FlagSet) {
" holding the leader lock (required if running locally with leader"+
" election enabled).",
)

}

// ToManagerOptions uses the flag set in f to configure options.
Expand Down
4 changes: 2 additions & 2 deletions internal/sdk/controllerutil/controllerutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ var (
func WaitForDeletion(ctx context.Context, cl client.Reader, o client.Object) error {
key := client.ObjectKeyFromObject(o)

return wait.PollUntilContextCancel(ctx, time.Millisecond*10, true, func(ctx context.Context) (done bool, err error) {
err = cl.Get(ctx, key, o)
return wait.PollUntilContextCancel(ctx, time.Millisecond*10, true, func(ctx context.Context) (bool, error) {
err := cl.Get(ctx, key, o)
if apierrors.IsNotFound(err) {
return true, nil
}
Expand Down
20 changes: 10 additions & 10 deletions internal/sdk/controllerutil/controllerutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
v1 "k8s.io/api/core/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
Expand All @@ -38,13 +38,13 @@ var _ = Describe("Controllerutil", func() {
var (
ctx context.Context
cancel context.CancelFunc
pod *v1.Pod
pod *corev1.Pod
client client.Client
)

BeforeEach(func() {
ctx, cancel = context.WithCancel(context.Background())
pod = &v1.Pod{
pod = &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "testName",
Namespace: "testNamespace",
Expand Down Expand Up @@ -95,13 +95,13 @@ var _ = Describe("Controllerutil", func() {
dependent = createObject(clusterScoped, types.NamespacedName{Namespace: "", Name: "dependent"})
supportsOwnerRef, err := SupportsOwnerReference(rm, owner, dependent)
Expect(supportsOwnerRef).To(BeTrue())
Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())
})
It("should be true for namespace-scoped dependents", func() {
dependent = createObject(namespaceScoped, types.NamespacedName{Namespace: "ns1", Name: "dependent"})
supportsOwnerRef, err := SupportsOwnerReference(rm, owner, dependent)
Expect(supportsOwnerRef).To(BeTrue())
Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())
})
})
When("owner is namespace scoped", func() {
Expand All @@ -112,22 +112,22 @@ var _ = Describe("Controllerutil", func() {
dependent = createObject(clusterScoped, types.NamespacedName{Namespace: "", Name: "dependent"})
supportsOwnerRef, err := SupportsOwnerReference(rm, owner, dependent)
Expect(supportsOwnerRef).To(BeFalse())
Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())
})
When("dependent is in owner namespace", func() {
It("should be true", func() {
dependent = createObject(namespaceScoped, types.NamespacedName{Namespace: "ns1", Name: "dependent"})
supportsOwnerRef, err := SupportsOwnerReference(rm, owner, dependent)
Expect(supportsOwnerRef).To(BeTrue())
Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())
})
})
When("dependent is not in owner namespace", func() {
It("should be false", func() {
dependent = createObject(namespaceScoped, types.NamespacedName{Namespace: "ns2", Name: "dependent"})
supportsOwnerRef, err := SupportsOwnerReference(rm, owner, dependent)
Expect(supportsOwnerRef).To(BeFalse())
Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())
})
})
})
Expand All @@ -144,13 +144,13 @@ var _ = Describe("Controllerutil", func() {
It("fails when owner REST mapping is missing", func() {
supportsOwnerRef, err := SupportsOwnerReference(rm, owner, dependent)
Expect(supportsOwnerRef).To(BeFalse())
Expect(err).NotTo(BeNil())
Expect(err).To(HaveOccurred())
})
It("fails when dependent REST mapping is missing", func() {
rm.Add(clusterScoped, meta.RESTScopeRoot)
supportsOwnerRef, err := SupportsOwnerReference(rm, owner, dependent)
Expect(supportsOwnerRef).To(BeFalse())
Expect(err).NotTo(BeNil())
Expect(err).To(HaveOccurred())
})
})
})
Expand Down
13 changes: 11 additions & 2 deletions internal/testutils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ type TestContext struct {

// NewTestContext returns a TestContext containing a new kubebuilder TestContext.
// Construct if your environment is connected to a live cluster, ex. for e2e tests.
func NewTestContext(binaryName string, env ...string) (tc TestContext, err error) {
func NewTestContext(binaryName string, env ...string) (TestContext, error) {
var (
tc TestContext
err error
)
if tc.TestContext, err = kbtestutils.NewTestContext(binaryName, env...); err != nil {
return tc, err
}
Expand All @@ -59,7 +63,12 @@ func NewTestContext(binaryName string, env ...string) (tc TestContext, err error
// NewPartialTestContext returns a TestContext containing a partial kubebuilder TestContext.
// This object needs to be populated with GVK information. The underlying TestContext is
// created directly rather than through a constructor so cluster-based setup is skipped.
func NewPartialTestContext(binaryName, dir string, env ...string) (tc TestContext, err error) {
func NewPartialTestContext(binaryName, dir string, env ...string) (TestContext, error) {
var (
tc TestContext
err error
)

cc := &kbtestutils.CmdContext{
Env: env,
}
Expand Down
2 changes: 1 addition & 1 deletion internal/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func getMostRecentTag(m debug.Module) string {
// This is necessary to handle projects that
// import this project at untagged commits.
if len(split) > 1 && sv.Patch > 0 {
sv.Patch -= 1
sv.Patch--
}
return fmt.Sprintf("v%s", sv.FinalizeVersion())
}
4 changes: 2 additions & 2 deletions pkg/client/actionclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
helmkube "helm.sh/helm/v3/pkg/kube"
"helm.sh/helm/v3/pkg/release"
"helm.sh/helm/v3/pkg/storage/driver"
apiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
apiextv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -350,7 +350,7 @@ func createPatch(existing runtime.Object, expected *resource.Info) ([]byte, apit

// On newer K8s versions, CRDs aren't unstructured but has this dedicated type
_, isCRDv1beta1 := versionedObject.(*apiextv1beta1.CustomResourceDefinition)
_, isCRDv1 := versionedObject.(*apiextv1.CustomResourceDefinition)
_, isCRDv1 := versionedObject.(*apiextensionsv1.CustomResourceDefinition)

if isUnstructured || isCRDv1beta1 || isCRDv1 {
// fall back to generic JSON merge patch
Expand Down
Loading

0 comments on commit c504538

Please sign in to comment.