Skip to content

Commit

Permalink
Merge pull request #146 from erikgb/remove-deprecated-use
Browse files Browse the repository at this point in the history
chore: remove use of deprecated APIs
  • Loading branch information
zoetrope authored Jul 25, 2024
2 parents 68417ba + f68d2b8 commit e097b49
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 31 deletions.
8 changes: 4 additions & 4 deletions charts/accurate/templates/generated/generated.yaml

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

4 changes: 2 additions & 2 deletions cmd/kubectl-accurate/sub/sub_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"fmt"

accuratev1 "github.com/cybozu-go/accurate/api/accurate/v1"
accuratev2 "github.com/cybozu-go/accurate/api/accurate/v2"
"github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -66,7 +66,7 @@ func (o *subCreateOpts) Run(ctx context.Context) error {
return fmt.Errorf("failed to get namespace %s: %w", o.name, err)
}

sn := &accuratev1.SubNamespace{}
sn := &accuratev2.SubNamespace{}
sn.Namespace = o.parent
sn.Name = o.name
sn.Spec.Labels = o.labels
Expand Down
4 changes: 2 additions & 2 deletions cmd/kubectl-accurate/sub/sub_cut.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"fmt"

accuratev1 "github.com/cybozu-go/accurate/api/accurate/v1"
accuratev2 "github.com/cybozu-go/accurate/api/accurate/v2"
"github.com/cybozu-go/accurate/pkg/constants"
"github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -70,7 +70,7 @@ func (o *subCutOpts) Run(ctx context.Context) error {

fmt.Fprintf(o.streams.Out, "cut %s as a root namespace\n", o.name)

sn := &accuratev1.SubNamespace{}
sn := &accuratev2.SubNamespace{}
sn.Namespace = parent
sn.Name = o.name

Expand Down
4 changes: 2 additions & 2 deletions cmd/kubectl-accurate/sub/sub_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"fmt"

accuratev1 "github.com/cybozu-go/accurate/api/accurate/v1"
accuratev2 "github.com/cybozu-go/accurate/api/accurate/v2"
"github.com/cybozu-go/accurate/pkg/constants"
"github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -61,7 +61,7 @@ func (o *subDeleteOpts) Run(ctx context.Context) error {
return fmt.Errorf("namespace %s is not a sub-namespace", o.name)
}

sn := &accuratev1.SubNamespace{}
sn := &accuratev2.SubNamespace{}
sn.Namespace = parent
sn.Name = o.name
if err := o.client.Delete(ctx, sn); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/kubectl-accurate/sub/sub_graft.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"fmt"

accuratev1 "github.com/cybozu-go/accurate/api/accurate/v1"
accuratev2 "github.com/cybozu-go/accurate/api/accurate/v2"
"github.com/cybozu-go/accurate/pkg/constants"
"github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -78,7 +78,7 @@ func (o *subGraftOpts) Run(ctx context.Context) error {
return fmt.Errorf("failed to update namespace %s: %w", o.name, err)
}

sn := &accuratev1.SubNamespace{}
sn := &accuratev2.SubNamespace{}
sn.Namespace = o.parent
sn.Name = o.name
if err := o.client.Create(ctx, sn); err != nil {
Expand Down
8 changes: 4 additions & 4 deletions cmd/kubectl-accurate/sub/sub_move.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"fmt"

accuratev1 "github.com/cybozu-go/accurate/api/accurate/v1"
accuratev2 "github.com/cybozu-go/accurate/api/accurate/v2"
"github.com/cybozu-go/accurate/pkg/constants"
"github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -85,13 +85,13 @@ func (o *subMoveOpts) Run(ctx context.Context) error {

fmt.Fprintf(o.streams.Out, "the parent has changed to %s\n", o.parent)

oldSN := &accuratev1.SubNamespace{}
oldSN := &accuratev2.SubNamespace{}
if err := o.client.Get(ctx, client.ObjectKey{Name: o.name, Namespace: orig}, oldSN); err != nil {
return fmt.Errorf("failed to get original SubNamespace %s/%s: %w", orig, o.name, err)
}

if !o.orphan {
oldSN := &accuratev1.SubNamespace{}
oldSN := &accuratev2.SubNamespace{}
oldSN.Namespace = orig
oldSN.Name = o.name
err := o.client.Delete(ctx, oldSN)
Expand All @@ -104,7 +104,7 @@ func (o *subMoveOpts) Run(ctx context.Context) error {
}
}

sn := &accuratev1.SubNamespace{}
sn := &accuratev2.SubNamespace{}
sn.Namespace = o.parent
sn.Name = o.name
sn.Spec.Labels = oldSN.Spec.Labels
Expand Down
8 changes: 4 additions & 4 deletions config/webhook/manifests.yaml

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

4 changes: 2 additions & 2 deletions e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,12 @@ var _ = Describe("kubectl accurate", func() {
}).Should(Succeed())
})

It("should convert SubNamespace to new version", func() {
It("should convert SubNamespace to older version", func() {
kubectlSafe(nil, "create", "ns", "rootv2")
kubectlSafe(nil, "accurate", "ns", "set-type", "rootv2", "root")
kubectlSafe(nil, "accurate", "sub", "create", "subv2", "rootv2")
kubectlSafe(nil, "get", "subnamespaces", "-n", "rootv2", "subv2")
kubectlSafe(nil, "get", "subnamespaces.v2alpha1.accurate.cybozu.com", "-n", "rootv2", "subv2")
kubectlSafe(nil, "get", "subnamespaces.v1.accurate.cybozu.com", "-n", "rootv2", "subv2")
})

It("should run other commands", func() {
Expand Down
18 changes: 9 additions & 9 deletions hooks/subnamespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

//+kubebuilder:webhook:path=/mutate-accurate-cybozu-com-v1-subnamespace,mutating=true,failurePolicy=fail,sideEffects=None,groups=accurate.cybozu.com,resources=subnamespaces,verbs=create;update,versions=v1,matchPolicy=Equivalent,name=subnamespace.accurate.cybozu.io,admissionReviewVersions={v1}
//+kubebuilder:webhook:path=/mutate-accurate-cybozu-com-v2-subnamespace,mutating=true,failurePolicy=fail,sideEffects=None,groups=accurate.cybozu.com,resources=subnamespaces,verbs=create;update,versions=v2,matchPolicy=Equivalent,name=subnamespace.accurate.cybozu.io,admissionReviewVersions={v1}

type subNamespaceMutator struct {
dec admission.Decoder
Expand All @@ -39,7 +39,7 @@ func (m *subNamespaceMutator) Handle(ctx context.Context, req admission.Request)
return admission.Allowed("")
}

sn := &accuratev1.SubNamespace{}
sn := &accuratev2.SubNamespace{}
if err := m.dec.Decode(req, sn); err != nil {
return admission.Errored(http.StatusBadRequest, err)
}
Expand All @@ -53,7 +53,7 @@ func (m *subNamespaceMutator) Handle(ctx context.Context, req admission.Request)
return admission.PatchResponseFromRaw(req.Object.Raw, data)
}

//+kubebuilder:webhook:path=/validate-accurate-cybozu-com-v1-subnamespace,mutating=false,failurePolicy=fail,sideEffects=None,groups=accurate.cybozu.com,resources=subnamespaces,verbs=create;delete,versions=v1,matchPolicy=Equivalent,name=vsubnamespace.kb.io,admissionReviewVersions={v1}
//+kubebuilder:webhook:path=/validate-accurate-cybozu-com-v2-subnamespace,mutating=false,failurePolicy=fail,sideEffects=None,groups=accurate.cybozu.com,resources=subnamespaces,verbs=create;delete,versions=v2,matchPolicy=Equivalent,name=vsubnamespace.kb.io,admissionReviewVersions={v1}

type subNamespaceValidator struct {
client.Client
Expand All @@ -66,13 +66,13 @@ var _ admission.Handler = &subNamespaceValidator{}
func (v *subNamespaceValidator) Handle(ctx context.Context, req admission.Request) admission.Response {
switch req.Operation {
case admissionv1.Create:
sn := &accuratev1.SubNamespace{}
sn := &accuratev2.SubNamespace{}
if err := v.dec.Decode(req, sn); err != nil {
return admission.Errored(http.StatusBadRequest, err)
}
return v.handleCreate(ctx, sn)
case admissionv1.Delete:
sn := &accuratev1.SubNamespace{}
sn := &accuratev2.SubNamespace{}
if err := v.dec.DecodeRaw(req.OldObject, sn); err != nil {
return admission.Errored(http.StatusBadRequest, err)
}
Expand All @@ -82,7 +82,7 @@ func (v *subNamespaceValidator) Handle(ctx context.Context, req admission.Reques
}
}

func (v *subNamespaceValidator) handleCreate(ctx context.Context, sn *accuratev1.SubNamespace) admission.Response {
func (v *subNamespaceValidator) handleCreate(ctx context.Context, sn *accuratev2.SubNamespace) admission.Response {
ns := &corev1.Namespace{}
if err := v.Get(ctx, client.ObjectKey{Name: sn.Namespace}, ns); err != nil {
return admission.Errored(http.StatusInternalServerError, err)
Expand Down Expand Up @@ -113,7 +113,7 @@ func (v *subNamespaceValidator) handleCreate(ctx context.Context, sn *accuratev1
return admission.Allowed("")
}

func (v *subNamespaceValidator) handleDelete(ctx context.Context, sn *accuratev1.SubNamespace) admission.Response {
func (v *subNamespaceValidator) handleDelete(ctx context.Context, sn *accuratev2.SubNamespace) admission.Response {
ns := &corev1.Namespace{}
if err := v.Get(ctx, client.ObjectKey{Name: sn.Name}, ns); err != nil {
if apierrors.IsNotFound(err) {
Expand Down Expand Up @@ -189,13 +189,13 @@ func SetupSubNamespaceWebhook(mgr manager.Manager, dec admission.Decoder, naming
m := &subNamespaceMutator{
dec: dec,
}
serv.Register("/mutate-accurate-cybozu-com-v1-subnamespace", &webhook.Admission{Handler: m})
serv.Register("/mutate-accurate-cybozu-com-v2-subnamespace", &webhook.Admission{Handler: m})

v := &subNamespaceValidator{
Client: mgr.GetClient(),
dec: dec,
namingPolicies: namingPolicyRegexps,
}
serv.Register("/validate-accurate-cybozu-com-v1-subnamespace", &webhook.Admission{Handler: v})
serv.Register("/validate-accurate-cybozu-com-v2-subnamespace", &webhook.Admission{Handler: v})
return nil
}

0 comments on commit e097b49

Please sign in to comment.