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

chore: change stored version of API to v2 #135

Merged
merged 1 commit into from
Jun 14, 2024
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
1 change: 1 addition & 0 deletions api/accurate/v2/subnamespace_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type SubNamespaceSpec struct {
}

//+kubebuilder:object:root=true
//+kubebuilder:storageversion
//+kubebuilder:subresource:status
//+genclient

Expand Down
1 change: 0 additions & 1 deletion api/accurate/v2alpha1/subnamespace_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ type SubNamespaceSpec struct {
}

//+kubebuilder:object:root=true
//+kubebuilder:storageversion
//+kubebuilder:subresource:status
//+genclient

Expand Down
4 changes: 2 additions & 2 deletions charts/accurate/templates/generated/crds.yaml

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

4 changes: 2 additions & 2 deletions config/crd/bases/accurate.cybozu.com_subnamespaces.yaml

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

6 changes: 3 additions & 3 deletions controllers/namespace_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"path"

accuratev2alpha1 "github.com/cybozu-go/accurate/api/accurate/v2alpha1"
accuratev2 "github.com/cybozu-go/accurate/api/accurate/v2"
utilerrors "github.com/cybozu-go/accurate/internal/util/errors"
"github.com/cybozu-go/accurate/pkg/constants"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -101,7 +101,7 @@ func (r *NamespaceReconciler) propagateMeta(ctx context.Context, ns, parent *cor
}

if _, ok := ns.Labels[constants.LabelParent]; ok {
subNS := &accuratev2alpha1.SubNamespace{}
subNS := &accuratev2.SubNamespace{}
err := r.Get(ctx, types.NamespacedName{Name: ns.Name, Namespace: parent.Name}, subNS)
if err != nil {
if !apierrors.IsNotFound(err) {
Expand Down Expand Up @@ -402,7 +402,7 @@ func (r *NamespaceReconciler) SetupWithManager(mgr ctrl.Manager) error {

return ctrl.NewControllerManagedBy(mgr).
For(&corev1.Namespace{}).
Watches(&accuratev2alpha1.SubNamespace{}, handler.Funcs{
Watches(&accuratev2.SubNamespace{}, handler.Funcs{
CreateFunc: func(ctx context.Context, ev event.CreateEvent, q workqueue.RateLimitingInterface) {
subNSHandler(ev.Object, q)
},
Expand Down
6 changes: 3 additions & 3 deletions controllers/namespace_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"time"

accuratev2alpha1 "github.com/cybozu-go/accurate/api/accurate/v2alpha1"
accuratev2 "github.com/cybozu-go/accurate/api/accurate/v2"
"github.com/cybozu-go/accurate/pkg/constants"
"github.com/cybozu-go/accurate/pkg/indexing"
. "github.com/onsi/ginkgo/v2"
Expand Down Expand Up @@ -431,7 +431,7 @@ var _ = Describe("Namespace controller", func() {
Expect(komega.Get(gcSec2)()).To(Succeed())

By("creating a SubNamespace for sub1 namespace")
sn := &accuratev2alpha1.SubNamespace{}
sn := &accuratev2.SubNamespace{}
sn.Namespace = "root"
sn.Name = "sub1"
sn.Spec.Labels = map[string]string{
Expand Down Expand Up @@ -483,7 +483,7 @@ var _ = Describe("Namespace controller", func() {
Expect(komega.Get(ns)()).To(Succeed())
Expect(ns.Labels).To(HaveKeyWithValue("bar.glob/l", "delete-me"))
Expect(ns.Annotations).To(HaveKeyWithValue("bar.glob/a", "delete-me"))
sn := &accuratev2alpha1.SubNamespace{}
sn := &accuratev2.SubNamespace{}
sn.Name = "pre-ssa-child"
sn.Namespace = "pre-ssa-root"
Expect(komega.Update(sn, func() {
Expand Down
8 changes: 4 additions & 4 deletions controllers/ssa_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"context"
"encoding/json"

accuratev2alpha1 "github.com/cybozu-go/accurate/api/accurate/v2alpha1"
accuratev2alpha1ac "github.com/cybozu-go/accurate/internal/applyconfigurations/accurate/v2alpha1"
accuratev2 "github.com/cybozu-go/accurate/api/accurate/v2"
accuratev2ac "github.com/cybozu-go/accurate/internal/applyconfigurations/accurate/v2"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/sets"
Expand Down Expand Up @@ -35,8 +35,8 @@ func upgradeManagedFields(ctx context.Context, c client.Client, obj client.Objec
return nil
}

func newSubNamespacePatch(ac *accuratev2alpha1ac.SubNamespaceApplyConfiguration) (*accuratev2alpha1.SubNamespace, client.Patch, error) {
sn := &accuratev2alpha1.SubNamespace{}
func newSubNamespacePatch(ac *accuratev2ac.SubNamespaceApplyConfiguration) (*accuratev2.SubNamespace, client.Patch, error) {
sn := &accuratev2.SubNamespace{}
sn.Name = *ac.Name
sn.Namespace = *ac.Namespace

Expand Down
18 changes: 9 additions & 9 deletions controllers/subnamespace_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"fmt"
"time"

accuratev2alpha1 "github.com/cybozu-go/accurate/api/accurate/v2alpha1"
accuratev2alpha1ac "github.com/cybozu-go/accurate/internal/applyconfigurations/accurate/v2alpha1"
accuratev2 "github.com/cybozu-go/accurate/api/accurate/v2"
accuratev2ac "github.com/cybozu-go/accurate/internal/applyconfigurations/accurate/v2"
utilerrors "github.com/cybozu-go/accurate/internal/util/errors"
"github.com/cybozu-go/accurate/pkg/constants"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -41,7 +41,7 @@ type SubNamespaceReconciler struct {
func (r *SubNamespaceReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
logger := log.FromContext(ctx)

sn := &accuratev2alpha1.SubNamespace{}
sn := &accuratev2.SubNamespace{}
if err := r.Get(ctx, req.NamespacedName, sn); err != nil {
return ctrl.Result{}, client.IgnoreNotFound(err)
}
Expand All @@ -62,7 +62,7 @@ func (r *SubNamespaceReconciler) Reconcile(ctx context.Context, req ctrl.Request
return ctrl.Result{}, nil
}

func (r *SubNamespaceReconciler) finalize(ctx context.Context, sn *accuratev2alpha1.SubNamespace) error {
func (r *SubNamespaceReconciler) finalize(ctx context.Context, sn *accuratev2.SubNamespace) error {
if !controllerutil.ContainsFinalizer(sn, constants.Finalizer) {
return nil
}
Expand Down Expand Up @@ -98,7 +98,7 @@ DELETE:
return r.Patch(ctx, sn, client.MergeFrom(orig))
}

func (r *SubNamespaceReconciler) reconcileNS(ctx context.Context, sn *accuratev2alpha1.SubNamespace) error {
func (r *SubNamespaceReconciler) reconcileNS(ctx context.Context, sn *accuratev2.SubNamespace) error {
logger := log.FromContext(ctx)

ns := &corev1.Namespace{}
Expand All @@ -119,9 +119,9 @@ func (r *SubNamespaceReconciler) reconcileNS(ctx context.Context, sn *accuratev2
logger.Info("created a sub namespace", "name", sn.Name)
}

ac := accuratev2alpha1ac.SubNamespace(sn.Name, sn.Namespace).
ac := accuratev2ac.SubNamespace(sn.Name, sn.Namespace).
WithStatus(
accuratev2alpha1ac.SubNamespaceStatus().
accuratev2ac.SubNamespaceStatus().
WithObservedGeneration(sn.Generation),
)

Expand All @@ -133,7 +133,7 @@ func (r *SubNamespaceReconciler) reconcileNS(ctx context.Context, sn *accuratev2
WithType(string(kstatus.ConditionStalled)).
WithStatus(metav1.ConditionTrue).
WithObservedGeneration(sn.Generation).
WithReason(accuratev2alpha1.SubNamespaceConflict).
WithReason(accuratev2.SubNamespaceConflict).
WithMessage("Conflicting namespace already exists"),
),
)
Expand Down Expand Up @@ -166,7 +166,7 @@ func (r *SubNamespaceReconciler) SetupWithManager(mgr ctrl.Manager) error {
}

return ctrl.NewControllerManagedBy(mgr).
For(&accuratev2alpha1.SubNamespace{}).
For(&accuratev2.SubNamespace{}).
Watches(&corev1.Namespace{}, handler.Funcs{
UpdateFunc: func(ctx context.Context, ev event.UpdateEvent, q workqueue.RateLimitingInterface) {
if ev.ObjectNew.GetDeletionTimestamp() != nil {
Expand Down
14 changes: 7 additions & 7 deletions controllers/subnamespace_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"time"

accuratev2alpha1 "github.com/cybozu-go/accurate/api/accurate/v2alpha1"
accuratev2 "github.com/cybozu-go/accurate/api/accurate/v2"
"github.com/cybozu-go/accurate/pkg/constants"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -55,7 +55,7 @@ var _ = Describe("SubNamespace controller", func() {
ns.Name = "test1"
Expect(k8sClient.Create(ctx, ns)).To(Succeed())

sn := &accuratev2alpha1.SubNamespace{}
sn := &accuratev2.SubNamespace{}
sn.Namespace = "test1"
sn.Name = "test1-sub1"
sn.Finalizers = []string{constants.Finalizer}
Expand Down Expand Up @@ -84,22 +84,22 @@ var _ = Describe("SubNamespace controller", func() {
ns2.Name = "test2-sub1"
Expect(k8sClient.Create(ctx, ns2)).To(Succeed())

sn := &accuratev2alpha1.SubNamespace{}
sn := &accuratev2.SubNamespace{}
sn.Namespace = "test2"
sn.Name = "test2-sub1"
Expect(k8sClient.Create(ctx, sn)).To(Succeed())

Eventually(komega.Object(sn)).Should(HaveField("Status.ObservedGeneration", BeNumerically(">", 0)))
Expect(sn.Status.Conditions).To(HaveLen(1))
Expect(sn.Status.Conditions[0].Reason).To(Equal(accuratev2alpha1.SubNamespaceConflict))
Expect(sn.Status.Conditions[0].Reason).To(Equal(accuratev2.SubNamespaceConflict))
})

It("should not delete a conflicting sub namespace", func() {
ns := &corev1.Namespace{}
ns.Name = "test3"
Expect(k8sClient.Create(ctx, ns)).To(Succeed())

sn := &accuratev2alpha1.SubNamespace{}
sn := &accuratev2.SubNamespace{}
sn.Namespace = "test3"
sn.Name = "test3-sub1"
sn.Finalizers = []string{constants.Finalizer}
Expand All @@ -114,7 +114,7 @@ var _ = Describe("SubNamespace controller", func() {
})()).To(Succeed())

Eventually(komega.Object(sn)).Should(HaveField("Status.Conditions", HaveLen(1)))
Expect(sn.Status.Conditions[0].Reason).To(Equal(accuratev2alpha1.SubNamespaceConflict))
Expect(sn.Status.Conditions[0].Reason).To(Equal(accuratev2.SubNamespaceConflict))

Expect(k8sClient.Delete(ctx, sn)).To(Succeed())

Expand All @@ -126,7 +126,7 @@ var _ = Describe("SubNamespace controller", func() {
ns.Name = "test4"
Expect(k8sClient.Create(ctx, ns)).To(Succeed())

sn := &accuratev2alpha1.SubNamespace{}
sn := &accuratev2.SubNamespace{}
sn.Namespace = "test4"
sn.Name = "test4-sub1"
Expect(k8sClient.Create(ctx, sn)).To(Succeed())
Expand Down
2 changes: 1 addition & 1 deletion controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ var _ = BeforeSuite(func() {
ns.Labels = map[string]string{constants.LabelType: constants.NSTypeRoot}
Expect(k8sClient.Create(context.Background(), ns)).To(Succeed())

sn := &accuratev2alpha1.SubNamespace{}
sn := &accuratev2.SubNamespace{}
sn.Name = "pre-ssa-child"
sn.Namespace = "pre-ssa-root"
sn.Spec.Labels = map[string]string{
Expand Down
Loading