Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ushitora-anqou committed Sep 3, 2024
1 parent 5a52993 commit 2d6a734
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 99 deletions.
18 changes: 3 additions & 15 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions charts/magout/templates/magout.anqou.net_mastodonservers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ spec:
type: object
replicas:
default: 1
format: int32
type: integer
resources:
description: ResourceRequirements describes the compute resource
Expand Down Expand Up @@ -231,6 +232,7 @@ spec:
type: object
replicas:
default: 1
format: int32
type: integer
resources:
description: ResourceRequirements describes the compute resource
Expand Down Expand Up @@ -359,6 +361,7 @@ spec:
type: object
replicas:
default: 1
format: int32
type: integer
resources:
description: ResourceRequirements describes the compute resource
Expand Down
12 changes: 6 additions & 6 deletions internal/controller/mastodonserver_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ import (
)

const (
prefix = "magout.anqou.net/"
labelMastodonServer = prefix + "mastodon-server"
labelDeployImage = prefix + "deploy-image"
domain = "magout.anqou.net"
labelMastodonServer = domain + "/mastodon-server"
labelDeployImage = domain + "/deploy-image"
)

// MastodonServerReconciler reconciles a MastodonServer object
type MastodonServerReconciler struct {
client client.Client
Client client.Client
Scheme *runtime.Scheme
}

Expand All @@ -46,7 +46,7 @@ func (r *MastodonServerReconciler) Reconcile(ctx context.Context, req ctrl.Reque
logger := log.FromContext(ctx)

var server magoutv1.MastodonServer
if err := r.client.Get(ctx, req.NamespacedName, &server); k8serrors.IsNotFound(err) {
if err := r.Client.Get(ctx, req.NamespacedName, &server); k8serrors.IsNotFound(err) {
logger.Info(
"MastodonServer not found",
"name", server.GetName(),
Expand Down Expand Up @@ -92,7 +92,7 @@ func (r *MastodonServerReconciler) createOrUpdateSidekiqDeployment(
deploy.SetName(fmt.Sprintf("%s-sidekiq", server.GetName()))
deploy.SetNamespace(server.GetNamespace())

result, err := ctrl.CreateOrUpdate(ctx, r.client, &deploy, func() error {
result, err := ctrl.CreateOrUpdate(ctx, r.Client, &deploy, func() error {
deploy.SetAnnotations(spec.Annotations)

selector := map[string]string{
Expand Down
123 changes: 57 additions & 66 deletions internal/controller/mastodonserver_controller_test.go
Original file line number Diff line number Diff line change
@@ -1,68 +1,59 @@
package controller

import (
"context"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

magoutv1 "github.com/ushitora-anqou/magout/api/v1"
)

var _ = Describe("MastodonServer Controller", func() {
Context("When reconciling a resource", func() {
const resourceName = "test-resource"

ctx := context.Background()

typeNamespacedName := types.NamespacedName{
Name: resourceName,
Namespace: "default", // TODO(user):Modify as needed
}
mastodonserver := &magoutv1.MastodonServer{}

BeforeEach(func() {
By("creating the custom resource for the Kind MastodonServer")
err := k8sClient.Get(ctx, typeNamespacedName, mastodonserver)
if err != nil && errors.IsNotFound(err) {
resource := &magoutv1.MastodonServer{
ObjectMeta: metav1.ObjectMeta{
Name: resourceName,
Namespace: "default",
},
// TODO(user): Specify other spec details if needed.
}
Expect(k8sClient.Create(ctx, resource)).To(Succeed())
}
})

AfterEach(func() {
// TODO(user): Cleanup logic after each test, like removing the resource instance.
resource := &magoutv1.MastodonServer{}
err := k8sClient.Get(ctx, typeNamespacedName, resource)
Expect(err).NotTo(HaveOccurred())

By("Cleanup the specific resource instance MastodonServer")
Expect(k8sClient.Delete(ctx, resource)).To(Succeed())
})
It("should successfully reconcile the resource", func() {
By("Reconciling the created resource")
controllerReconciler := &MastodonServerReconciler{
Client: k8sClient,
Scheme: k8sClient.Scheme(),
}

_, err := controllerReconciler.Reconcile(ctx, reconcile.Request{
NamespacedName: typeNamespacedName,
})
Expect(err).NotTo(HaveOccurred())
// TODO(user): Add more specific assertions depending on your controller's reconciliation logic.
// Example: If you expect a certain status condition after reconciliation, verify it here.
})
})
})
// import (
// . "github.com/onsi/ginkgo/v2"
// . "github.com/onsi/gomega"
// )

// var _ = Describe("MastodonServer Controller", func() {
// Context("When reconciling a resource", func() {
// const resourceName = "test-resource"
//
// ctx := context.Background()
//
// typeNamespacedName := types.NamespacedName{
// Name: resourceName,
// Namespace: "default", // TODO(user):Modify as needed
// }
// mastodonserver := &magoutv1.MastodonServer{}
//
// BeforeEach(func() {
// By("creating the custom resource for the Kind MastodonServer")
// err := k8sClient.Get(ctx, typeNamespacedName, mastodonserver)
// if err != nil && errors.IsNotFound(err) {
// resource := &magoutv1.MastodonServer{
// ObjectMeta: metav1.ObjectMeta{
// Name: resourceName,
// Namespace: "default",
// },
// // TODO(user): Specify other spec details if needed.
// }
// Expect(k8sClient.Create(ctx, resource)).To(Succeed())
// }
// })
//
// AfterEach(func() {
// // TODO(user): Cleanup logic after each test, like removing the resource instance.
// resource := &magoutv1.MastodonServer{}
// err := k8sClient.Get(ctx, typeNamespacedName, resource)
// Expect(err).NotTo(HaveOccurred())
//
// By("Cleanup the specific resource instance MastodonServer")
// Expect(k8sClient.Delete(ctx, resource)).To(Succeed())
// })
// It("should successfully reconcile the resource", func() {
// By("Reconciling the created resource")
// controllerReconciler := &MastodonServerReconciler{
// Client: k8sClient,
// Scheme: k8sClient.Scheme(),
// }
//
// _, err := controllerReconciler.Reconcile(ctx, reconcile.Request{
// NamespacedName: typeNamespacedName,
// })
// Expect(err).NotTo(HaveOccurred())
// // TODO(user): Add more specific assertions depending on your controller's reconciliation logic.
// // Example: If you expect a certain status condition after reconciliation, verify it here.
// })
// })
// })
24 changes: 12 additions & 12 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package e2e

import (
. "github.com/onsi/ginkgo/v2"
//. "github.com/onsi/gomega"
)

var _ = Describe("controller", Ordered, func() {
Context("Operator", func() {
It("should run successfully", func() {
return
})
})
})
// import (
// . "github.com/onsi/ginkgo/v2"
// . "github.com/onsi/gomega"
// )
//
// var _ = Describe("controller", Ordered, func() {
// Context("Operator", func() {
// It("should run successfully", func() {
// return
// })
// })
// })

0 comments on commit 2d6a734

Please sign in to comment.