Skip to content

Commit

Permalink
fix: import terminating ns
Browse files Browse the repository at this point in the history
  • Loading branch information
mhrabovcin committed Jun 1, 2023
1 parent 76c5aca commit b30a0a2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
9 changes: 3 additions & 6 deletions pkg/rewriter/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
)

var _ ResourceRewriter = (*deletedNamespace)(nil)
Expand All @@ -21,12 +22,8 @@ type deletedNamespace struct{}

func (deletedNamespace) BeforeImport(u *unstructured.Unstructured) error {
// Only process Namespace kinds
if u.GetKind() != "Namespace" && u.GetAPIVersion() != "" {
return nil
}

// Only deleted namespaces could be in Terminating phase
if u.GetDeletionTimestamp() == nil {
isNamespaceKind := MatchGVK(schema.FromAPIVersionAndKind("v1", "Namespace"))
if !isNamespaceKind(u) {
return nil
}

Expand Down
8 changes: 8 additions & 0 deletions pkg/rewriter/namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import (

func TestDeletedNamespace_ReplaceStatus(t *testing.T) {
ns := &corev1.Namespace{
TypeMeta: metav1.TypeMeta{
Kind: "Namespace",
APIVersion: "v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: "test",
DeletionTimestamp: &metav1.Time{
Expand All @@ -36,6 +40,10 @@ func TestDeletedNamespace_ReplaceStatus(t *testing.T) {

func TestDeletedNamespace_Active(t *testing.T) {
ns := &corev1.Namespace{
TypeMeta: metav1.TypeMeta{
Kind: "Namespace",
APIVersion: "v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: "test",
},
Expand Down

0 comments on commit b30a0a2

Please sign in to comment.