diff --git a/charts/accurate/templates/generated/generated.yaml b/charts/accurate/templates/generated/generated.yaml index c85756b..49c3850 100644 --- a/charts/accurate/templates/generated/generated.yaml +++ b/charts/accurate/templates/generated/generated.yaml @@ -231,7 +231,7 @@ webhooks: service: name: '{{ template "accurate.fullname" . }}-webhook-service' namespace: '{{ .Release.Namespace }}' - path: /mutate-accurate-cybozu-com-v1-subnamespace + path: /mutate-accurate-cybozu-com-v2-subnamespace failurePolicy: Fail matchPolicy: Equivalent name: subnamespace.accurate.cybozu.io @@ -239,7 +239,7 @@ webhooks: - apiGroups: - accurate.cybozu.com apiVersions: - - v1 + - v2 operations: - CREATE - UPDATE @@ -286,7 +286,7 @@ webhooks: service: name: '{{ template "accurate.fullname" . }}-webhook-service' namespace: '{{ .Release.Namespace }}' - path: /validate-accurate-cybozu-com-v1-subnamespace + path: /validate-accurate-cybozu-com-v2-subnamespace failurePolicy: Fail matchPolicy: Equivalent name: vsubnamespace.kb.io @@ -294,7 +294,7 @@ webhooks: - apiGroups: - accurate.cybozu.com apiVersions: - - v1 + - v2 operations: - CREATE - DELETE diff --git a/cmd/kubectl-accurate/sub/sub_create.go b/cmd/kubectl-accurate/sub/sub_create.go index 41d5d0f..23e523d 100644 --- a/cmd/kubectl-accurate/sub/sub_create.go +++ b/cmd/kubectl-accurate/sub/sub_create.go @@ -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" @@ -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 diff --git a/cmd/kubectl-accurate/sub/sub_cut.go b/cmd/kubectl-accurate/sub/sub_cut.go index a61f683..d75e0d6 100644 --- a/cmd/kubectl-accurate/sub/sub_cut.go +++ b/cmd/kubectl-accurate/sub/sub_cut.go @@ -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" @@ -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 diff --git a/cmd/kubectl-accurate/sub/sub_delete.go b/cmd/kubectl-accurate/sub/sub_delete.go index 2338371..06bb35a 100644 --- a/cmd/kubectl-accurate/sub/sub_delete.go +++ b/cmd/kubectl-accurate/sub/sub_delete.go @@ -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" @@ -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 { diff --git a/cmd/kubectl-accurate/sub/sub_graft.go b/cmd/kubectl-accurate/sub/sub_graft.go index f4b39c7..6620d59 100644 --- a/cmd/kubectl-accurate/sub/sub_graft.go +++ b/cmd/kubectl-accurate/sub/sub_graft.go @@ -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" @@ -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 { diff --git a/cmd/kubectl-accurate/sub/sub_move.go b/cmd/kubectl-accurate/sub/sub_move.go index 4e37216..eadfb77 100644 --- a/cmd/kubectl-accurate/sub/sub_move.go +++ b/cmd/kubectl-accurate/sub/sub_move.go @@ -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" @@ -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) @@ -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 diff --git a/config/webhook/manifests.yaml b/config/webhook/manifests.yaml index b09dd16..7d6c98f 100644 --- a/config/webhook/manifests.yaml +++ b/config/webhook/manifests.yaml @@ -10,7 +10,7 @@ webhooks: service: name: webhook-service namespace: system - path: /mutate-accurate-cybozu-com-v1-subnamespace + path: /mutate-accurate-cybozu-com-v2-subnamespace failurePolicy: Fail matchPolicy: Equivalent name: subnamespace.accurate.cybozu.io @@ -18,7 +18,7 @@ webhooks: - apiGroups: - accurate.cybozu.com apiVersions: - - v1 + - v2 operations: - CREATE - UPDATE @@ -58,7 +58,7 @@ webhooks: service: name: webhook-service namespace: system - path: /validate-accurate-cybozu-com-v1-subnamespace + path: /validate-accurate-cybozu-com-v2-subnamespace failurePolicy: Fail matchPolicy: Equivalent name: vsubnamespace.kb.io @@ -66,7 +66,7 @@ webhooks: - apiGroups: - accurate.cybozu.com apiVersions: - - v1 + - v2 operations: - CREATE - DELETE diff --git a/e2e/e2e_test.go b/e2e/e2e_test.go index 2541529..f444aef 100644 --- a/e2e/e2e_test.go +++ b/e2e/e2e_test.go @@ -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() { diff --git a/hooks/subnamespace.go b/hooks/subnamespace.go index 8c8e469..3193074 100644 --- a/hooks/subnamespace.go +++ b/hooks/subnamespace.go @@ -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 @@ -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) } @@ -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 @@ -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) } @@ -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) @@ -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) { @@ -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 }