Skip to content

Commit

Permalink
update go api
Browse files Browse the repository at this point in the history
  • Loading branch information
takara9 committed May 22, 2024
1 parent 3e9406e commit f9269d4
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 29 deletions.
6 changes: 2 additions & 4 deletions api/v1beta2/mysqlcluster_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ func makeMySQLCluster() *mocov1beta2.MySQLCluster {
},
Spec: mocov1beta2.PersistentVolumeClaimSpecApplyConfiguration(*corev1ac.PersistentVolumeClaimSpec().
WithStorageClassName("default").
WithResources(corev1ac.ResourceRequirements().
WithRequests(corev1.ResourceList{
corev1.ResourceStorage: resource.MustParse("1Gi"),
})),
WithResources(
corev1ac.VolumeResourceRequirements().WithRequests(corev1.ResourceList{corev1.ResourceStorage: resource.MustParse("1Gi")})),
),
},
},
Expand Down
14 changes: 10 additions & 4 deletions api/v1beta2/webhook_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"sigs.k8s.io/controller-runtime/pkg/envtest"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
"sigs.k8s.io/controller-runtime/pkg/webhook"
)

// These tests use Ginkgo (BDD-style Go testing framework). Refer to
Expand Down Expand Up @@ -80,11 +82,15 @@ var _ = BeforeSuite(func() {
webhookInstallOptions := &testEnv.CRDInstallOptions.WebhookOptions
mgr, err := ctrl.NewManager(cfg, ctrl.Options{
Scheme: scheme,
Host: webhookInstallOptions.LocalServingHost,
Port: webhookInstallOptions.LocalServingPort,
CertDir: webhookInstallOptions.LocalServingCertDir,
WebhookServer: webhook.NewServer(webhook.Options{
Host: webhookInstallOptions.LocalServingHost,
Port: webhookInstallOptions.LocalServingPort,
CertDir: webhookInstallOptions.LocalServingCertDir,
}),
LeaderElection: false,
MetricsBindAddress: "0",
Metrics: metricsserver.Options{
BindAddress: "0",
},
})
Expect(err).NotTo(HaveOccurred())

Expand Down
5 changes: 4 additions & 1 deletion clustering/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/manager"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
)

func testSetupResources(ctx context.Context, replicas int32, sourceSecret string) {
Expand Down Expand Up @@ -127,7 +128,9 @@ var _ = Describe("manager", func() {
mgr, err = ctrl.NewManager(cfg, ctrl.Options{
Scheme: scheme,
LeaderElection: false,
MetricsBindAddress: "0",
Metrics: metricsserver.Options{
BindAddress: "0",
},
})
Expect(err).NotTo(HaveOccurred())

Expand Down
15 changes: 11 additions & 4 deletions cmd/moco-controller/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
k8smetrics "sigs.k8s.io/controller-runtime/pkg/metrics"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
"sigs.k8s.io/controller-runtime/pkg/webhook"
// +kubebuilder:scaffold:imports
)

Expand Down Expand Up @@ -68,15 +70,20 @@ func subMain(ns, addr string, port int) error {

mgr, err := ctrl.NewManager(restCfg, ctrl.Options{
Scheme: scheme,
MetricsBindAddress: config.metricsAddr,
Metrics: metricsserver.Options{
BindAddress: config.metricsAddr,
},
HealthProbeBindAddress: config.probeAddr,
PprofBindAddress: config.pprofAddr,
LeaderElection: true,
LeaderElectionID: config.leaderElectionID,
LeaderElectionNamespace: ns,
Host: addr,
Port: port,
CertDir: config.certDir,
WebhookServer: webhook.NewServer(webhook.Options{
Host: addr,
Port: port,
CertDir: config.certDir,
}),

})
if err != nil {
setupLog.Error(err, "unable to start manager")
Expand Down
10 changes: 7 additions & 3 deletions controllers/mysqlcluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,13 @@ func testNewMySQLCluster(ns string) *mocov1beta2.MySQLCluster {
{
ObjectMeta: mocov1beta2.ObjectMeta{Name: "mysql-data"},
Spec: mocov1beta2.PersistentVolumeClaimSpecApplyConfiguration(*corev1ac.PersistentVolumeClaimSpec().
WithStorageClassName("hoge").WithResources(corev1ac.ResourceRequirements().
WithRequests(corev1.ResourceList{corev1.ResourceStorage: *resource.NewQuantity(1<<30, resource.BinarySI)}),
)),
WithStorageClassName("hoge").
WithResources(
corev1ac.VolumeResourceRequirements().WithRequests(
corev1.ResourceList{corev1.ResourceStorage: *resource.NewQuantity(1<<30, resource.BinarySI)},
),
),
),
},
}
return cluster
Expand Down
5 changes: 4 additions & 1 deletion controllers/pod_watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"k8s.io/utils/ptr"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
)

func testNewSts(ns string) *appsv1.StatefulSet {
Expand Down Expand Up @@ -64,7 +65,9 @@ var _ = Describe("PodWatcher", func() {
mgr, err := ctrl.NewManager(cfg, ctrl.Options{
Scheme: scheme,
LeaderElection: false,
MetricsBindAddress: "0",
Metrics: metricsserver.Options{
BindAddress: "0",
},
})
Expect(err).ToNot(HaveOccurred())

Expand Down
12 changes: 6 additions & 6 deletions controllers/pvc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func TestNeedResizePVC(t *testing.T) {
},
Spec: corev1.PersistentVolumeClaimSpec{
StorageClassName: ptr.To[string]("default"),
Resources: corev1.ResourceRequirements{
Resources: corev1.VolumeResourceRequirements{
Requests: corev1.ResourceList{corev1.ResourceStorage: resource.MustParse("1Gi")},
},
},
Expand All @@ -282,7 +282,7 @@ func TestNeedResizePVC(t *testing.T) {
pvc := mocov1beta2.PersistentVolumeClaim{
ObjectMeta: mocov1beta2.ObjectMeta{Name: "new-data"},
Spec: mocov1beta2.PersistentVolumeClaimSpecApplyConfiguration(*corev1ac.PersistentVolumeClaimSpec().
WithStorageClassName("default").WithResources(corev1ac.ResourceRequirements().
WithStorageClassName("default").WithResources(corev1ac.VolumeResourceRequirements().
WithRequests(corev1.ResourceList{corev1.ResourceStorage: resource.MustParse("1Gi")}),
)),
}
Expand All @@ -299,7 +299,7 @@ func TestNeedResizePVC(t *testing.T) {
pvc := mocov1beta2.PersistentVolumeClaim{
ObjectMeta: mocov1beta2.ObjectMeta{Name: "new-data"},
Spec: mocov1beta2.PersistentVolumeClaimSpecApplyConfiguration(*corev1ac.PersistentVolumeClaimSpec().
WithStorageClassName("default").WithResources(corev1ac.ResourceRequirements().
WithStorageClassName("default").WithResources(corev1ac.VolumeResourceRequirements().
WithRequests(corev1.ResourceList{corev1.ResourceStorage: resource.MustParse("1Gi")}),
)),
}
Expand All @@ -314,7 +314,7 @@ func TestNeedResizePVC(t *testing.T) {
},
Spec: corev1.PersistentVolumeClaimSpec{
StorageClassName: ptr.To[string]("default"),
Resources: corev1.ResourceRequirements{
Resources: corev1.VolumeResourceRequirements{
Requests: corev1.ResourceList{corev1.ResourceStorage: resource.MustParse("2Gi")},
},
},
Expand Down Expand Up @@ -374,7 +374,7 @@ func newMySQLClusterWithVolumeSize(size resource.Quantity) *mocov1beta2.MySQLClu
{
ObjectMeta: mocov1beta2.ObjectMeta{Name: "mysql-data"},
Spec: mocov1beta2.PersistentVolumeClaimSpecApplyConfiguration(*corev1ac.PersistentVolumeClaimSpec().
WithStorageClassName("default").WithResources(corev1ac.ResourceRequirements().
WithStorageClassName("default").WithResources(corev1ac.VolumeResourceRequirements().
WithRequests(corev1.ResourceList{corev1.ResourceStorage: size}),
)),
},
Expand Down Expand Up @@ -406,7 +406,7 @@ func newStatefulSetWithVolumeSize(size resource.Quantity) *appsv1.StatefulSet {
},
Spec: corev1.PersistentVolumeClaimSpec{
StorageClassName: ptr.To[string]("default"),
Resources: corev1.ResourceRequirements{
Resources: corev1.VolumeResourceRequirements{
Requests: corev1.ResourceList{corev1.ResourceStorage: size},
},
},
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ require (
google.golang.org/protobuf v1.34.1
k8s.io/api v0.30.1
k8s.io/apimachinery v0.30.1
k8s.io/cli-runtime v0.30.1
k8s.io/cli-runtime v0.28.10
k8s.io/client-go v0.30.1
k8s.io/klog/v2 v2.120.1
k8s.io/kubectl v0.30.1
k8s.io/kubectl v0.28.10
k8s.io/utils v0.0.0-20240502163921-fe8a2dddb1d0
sigs.k8s.io/controller-runtime v0.18.2
)
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,8 @@ k8s.io/apiextensions-apiserver v0.30.0 h1:jcZFKMqnICJfRxTgnC4E+Hpcq8UEhT8B2lhBcQ
k8s.io/apiextensions-apiserver v0.30.0/go.mod h1:N9ogQFGcrbWqAY9p2mUAL5mGxsLqwgtUce127VtRX5Y=
k8s.io/apimachinery v0.30.1 h1:ZQStsEfo4n65yAdlGTfP/uSHMQSoYzU/oeEbkmF7P2U=
k8s.io/apimachinery v0.30.1/go.mod h1:iexa2somDaxdnj7bha06bhb43Zpa6eWH8N8dbqVjTUc=
k8s.io/cli-runtime v0.30.1 h1:kSBBpfrJGS6lllc24KeniI9JN7ckOOJKnmFYH1RpTOw=
k8s.io/cli-runtime v0.30.1/go.mod h1:zhHgbqI4J00pxb6gM3gJPVf2ysDjhQmQtnTxnMScab8=
k8s.io/cli-runtime v0.28.10 h1:H+x/4DA3FoOcDXmExdf5Dx4eUPfSV4qzxVmBFtK534U=
k8s.io/cli-runtime v0.28.10/go.mod h1:vXWKeqv5sH6k/vDwHAjmcgJCcXq/OGyFUwifmN4M0xE=
k8s.io/client-go v0.30.1 h1:uC/Ir6A3R46wdkgCV3vbLyNOYyCJ8oZnjtJGKfytl/Q=
k8s.io/client-go v0.30.1/go.mod h1:wrAqLNs2trwiCH/wxxmT/x3hKVH9PuV0GGW0oDoHVqc=
k8s.io/component-base v0.30.1 h1:bvAtlPh1UrdaZL20D9+sWxsJljMi0QZ3Lmw+kmZAaxQ=
Expand All @@ -450,8 +450,8 @@ k8s.io/klog/v2 v2.120.1 h1:QXU6cPEOIslTGvZaXvFWiP9VKyeet3sawzTOvdXb4Vw=
k8s.io/klog/v2 v2.120.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 h1:BZqlfIlq5YbRMFko6/PM7FjZpUb45WallggurYhKGag=
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340/go.mod h1:yD4MZYeKMBwQKVht279WycxKyM84kkAx2DPrTXaeb98=
k8s.io/kubectl v0.30.1 h1:sHFIRI3oP0FFZmBAVEE8ErjnTyXDPkBcvO88mH9RjuY=
k8s.io/kubectl v0.30.1/go.mod h1:7j+L0Cc38RYEcx+WH3y44jRBe1Q1jxdGPKkX0h4iDq0=
k8s.io/kubectl v0.28.10 h1:ljlWrQVqKZspYESo4u570s3/BbnhiJ2z5LspzIKRSDM=
k8s.io/kubectl v0.28.10/go.mod h1:A1imFpT+xfaRkf+jN1yGHkAnq7hukF74i2ny/iXjbHc=
k8s.io/utils v0.0.0-20240502163921-fe8a2dddb1d0 h1:jgGTlFYnhF1PM1Ax/lAlxUPE+KfCIXHaathvJg1C3ak=
k8s.io/utils v0.0.0-20240502163921-fe8a2dddb1d0/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
sigs.k8s.io/controller-runtime v0.18.2 h1:RqVW6Kpeaji67CY5nPEfRz6ZfFMk0lWQlNrLqlNpx+Q=
Expand Down

0 comments on commit f9269d4

Please sign in to comment.