Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clean the unused code and prune vineyardctl dependency #1562

Merged
merged 7 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ import (
"context"
"crypto/tls"
"fmt"
"io"
"net"
"path/filepath"
"testing"
"time"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/avast/retry-go"
"github.com/stretchr/testify/assert"
"github.com/v6d-io/v6d/k8s/pkg/log"

admissionv1beta1 "k8s.io/api/admission/v1beta1"
//+kubebuilder:scaffold:imports
Expand All @@ -47,45 +49,39 @@ var (
cancel context.CancelFunc
)

func TestAPIs(t *testing.T) {
RegisterFailHandler(Fail)

RunSpecs(t,
"Webhook Suite")
}

var _ = BeforeSuite(func() {
func Test_webhook(t *testing.T) {
var GinkgoWriter io.Writer
logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true)))

ctx, cancel = context.WithCancel(context.TODO())

By("bootstrapping test environment")
log.Info("Bootstrapping test environment")
testEnv = &envtest.Environment{
CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crd", "bases")},
ErrorIfCRDPathMissing: false,
WebhookInstallOptions: envtest.WebhookInstallOptions{
Paths: []string{filepath.Join("..", "..", "..", "config", "webhook")},
Paths: []string{filepath.Join("..", "..", "..", "config", "webhook", "manifests.yaml")},
},
}

var err error
// cfg is defined in this file globally.
cfg, err = testEnv.Start()
Expect(err).NotTo(HaveOccurred())
Expect(cfg).NotTo(BeNil())
assert.NoError(t, err)
assert.NotNil(t, cfg)

scheme := runtime.NewScheme()
err = AddToScheme(scheme)
Expect(err).NotTo(HaveOccurred())
assert.NoError(t, err)

err = admissionv1beta1.AddToScheme(scheme)
Expect(err).NotTo(HaveOccurred())
assert.NoError(t, err)

//+kubebuilder:scaffold:scheme

k8sClient, err = client.New(cfg, client.Options{Scheme: scheme})
Expect(err).NotTo(HaveOccurred())
Expect(k8sClient).NotTo(BeNil())
assert.NoError(t, err)
assert.NotNil(t, k8sClient)

// start webhook server using Manager
webhookInstallOptions := &testEnv.WebhookInstallOptions
Expand All @@ -97,26 +93,25 @@ var _ = BeforeSuite(func() {
LeaderElection: false,
MetricsBindAddress: "0",
})
Expect(err).NotTo(HaveOccurred())
assert.NoError(t, err)

err = (&Operation{}).SetupWebhookWithManager(mgr)
Expect(err).NotTo(HaveOccurred())
assert.NoError(t, err)

err = (&Sidecar{}).SetupWebhookWithManager(mgr)
Expect(err).NotTo(HaveOccurred())
assert.NoError(t, err)

err = (&Backup{}).SetupWebhookWithManager(mgr)
Expect(err).NotTo(HaveOccurred())
assert.NoError(t, err)

err = (&Recover{}).SetupWebhookWithManager(mgr)
Expect(err).NotTo(HaveOccurred())
assert.NoError(t, err)

//+kubebuilder:scaffold:webhook

go func() {
defer GinkgoRecover()
err = mgr.Start(ctx)
Expect(err).NotTo(HaveOccurred())
assert.NoError(t, err)
}()

// wait for the webhook server to get ready
Expand All @@ -126,7 +121,7 @@ var _ = BeforeSuite(func() {
webhookInstallOptions.LocalServingHost,
webhookInstallOptions.LocalServingPort,
)
Eventually(func() error {
err = retry.Do(func() error {
conn, err := tls.DialWithDialer(
dialer,
"tcp",
Expand All @@ -138,12 +133,12 @@ var _ = BeforeSuite(func() {
}
conn.Close()
return nil
}).Should(Succeed())
}, 60)
})
assert.NoError(t, err)

var _ = AfterSuite(func() {
cancel()
By("tearing down the test environment")
err := testEnv.Stop()
Expect(err).NotTo(HaveOccurred())
})
time.Sleep(1 * time.Second)
log.Info("tearing down the test environment")
err = testEnv.Stop()
assert.NoError(t, err)
}
9 changes: 0 additions & 9 deletions k8s/cmd/commands/client/ls_metadatas.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ limitations under the License.
package client

import (
"os"

"github.com/spf13/cobra"
"github.com/v6d-io/v6d/k8s/cmd/commands/flags"
"github.com/v6d-io/v6d/k8s/cmd/commands/util"
Expand Down Expand Up @@ -89,10 +87,3 @@ func init() {
flags.ApplyLsOpts(lsMetadatas)
flags.ApplyOutputOpts(lsMetadatas)
}

func DisableStdout() *os.File {
stdout := os.Stdout
os.Stdout, _ = os.Open(os.DevNull)

return stdout
}
2 changes: 0 additions & 2 deletions k8s/cmd/commands/deploy/deploy_recover_job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package deploy

import (
"context"
"fmt"
"reflect"
"testing"

Expand Down Expand Up @@ -314,7 +313,6 @@ func Test_getRecoverObjectsFromTemplate_third(t *testing.T) {
}
for i := range got {
if !reflect.DeepEqual(*got[i], *(tt.want)[i]) {
fmt.Println(*got[i])
t.Errorf("getRecoverObjectsFromTemplate() = %+v, want %+v", got, tt.want)
}
}
Expand Down
2 changes: 0 additions & 2 deletions k8s/cmd/commands/sidecar/inject_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,6 @@ spec:
return
}
if !reflect.DeepEqual(got, tt.want) {
fmt.Println(got)
fmt.Println(tt.want)
t.Errorf("GetWorkloadObj() = %v, want %v", got, tt.want)
}
})
Expand Down
4 changes: 0 additions & 4 deletions k8s/cmd/commands/util/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ func Examples(examples string) string {
return formatter{examples}.trim().tab().indent().string
}

func Docs(yamls string) string {
return formatter{yamls}.doc().string
}

type formatter struct {
string
}
Expand Down
5 changes: 0 additions & 5 deletions k8s/cmd/commands/util/usage/md_docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,6 @@ func printOptions(buf *bytes.Buffer, titleLevel string, cmd *cobra.Command, name
return nil
}

// GenMarkdown creates markdown output.
func GenMarkdown(cmd *cobra.Command, w io.Writer) error {
return GenMarkdownCustom(cmd, w, func(s string) string { return s })
}

// GenMarkdownCustom creates custom markdown output.
func GenMarkdownCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string) string) error {
cmd.InitDefaultHelpCmd()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ limitations under the License.
package k8s

import (
"io"
"path/filepath"
"testing"
"time"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/stretchr/testify/assert"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -27,6 +28,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log/zap"

k8sv1alpha1 "github.com/v6d-io/v6d/k8s/apis/k8s/v1alpha1"
"github.com/v6d-io/v6d/k8s/pkg/log"
//+kubebuilder:scaffold:imports
)

Expand All @@ -37,16 +39,11 @@ var cfg *rest.Config
var k8sClient client.Client
var testEnv *envtest.Environment

func TestAPIs(t *testing.T) {
RegisterFailHandler(Fail)

RunSpecs(t, "Controller Suite")
}

var _ = BeforeSuite(func() {
func Test_controller(t *testing.T) {
var GinkgoWriter io.Writer
logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true)))

By("bootstrapping test environment")
log.Info("Bootstrapping test environment")
testEnv = &envtest.Environment{
CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")},
ErrorIfCRDPathMissing: true,
Expand All @@ -55,22 +52,20 @@ var _ = BeforeSuite(func() {
var err error
// cfg is defined in this file globally.
cfg, err = testEnv.Start()
Expect(err).NotTo(HaveOccurred())
Expect(cfg).NotTo(BeNil())
assert.NoError(t, err)
assert.NotNil(t, cfg)

err = k8sv1alpha1.AddToScheme(scheme.Scheme)
Expect(err).NotTo(HaveOccurred())
assert.NoError(t, err)

//+kubebuilder:scaffold:scheme

k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme})
Expect(err).NotTo(HaveOccurred())
Expect(k8sClient).NotTo(BeNil())
assert.NoError(t, err)
assert.NotNil(t, k8sClient)

}, 60)

var _ = AfterSuite(func() {
By("tearing down the test environment")
err := testEnv.Stop()
Expect(err).NotTo(HaveOccurred())
})
time.Sleep(1 * time.Second)
log.Info("tearing down the test environment")
err = testEnv.Stop()
assert.NoError(t, err)
}
4 changes: 0 additions & 4 deletions k8s/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ require (
github.com/ghodss/yaml v1.0.0
github.com/go-logr/logr v1.2.3
github.com/olekukonko/tablewriter v0.0.4
github.com/onsi/ginkgo v1.16.5
github.com/onsi/gomega v1.20.1
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v1.4.0
github.com/spf13/pflag v1.0.5
Expand Down Expand Up @@ -85,7 +83,6 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/selinux v1.10.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
Expand Down Expand Up @@ -129,7 +126,6 @@ require (
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiserver v0.25.10 // indirect
Expand Down
Loading