-
Notifications
You must be signed in to change notification settings - Fork 8
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
[Task] Add namespace crud #227
Conversation
0e15586
to
647745b
Compare
647745b
to
b14d505
Compare
Codecov Report
@@ Coverage Diff @@
## develop #227 +/- ##
===========================================
- Coverage 78.46% 78.21% -0.26%
===========================================
Files 50 53 +3
Lines 2498 2639 +141
===========================================
+ Hits 1960 2064 +104
- Misses 407 437 +30
- Partials 131 138 +7
Continue to review full report at Codecov.
|
src/entity/namespace.go
Outdated
|
||
// the const for NamespaceCollectionName | ||
const ( | ||
NamespaceCollectionName string = "namespace" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
namespaces
src/entity/namespace.go
Outdated
type Namespace struct { | ||
ID bson.ObjectId `bson:"_id,omitempty" json:"id" validate:"-"` | ||
Name string `bson:"name" json:"name" validate:"required,k8sname"` | ||
Labels map[string]string `bson:"labels,omitempty" json:"labels" validate:"required,dive,keys,alphanum,endkeys,required,alphanum"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we don't need labels here
src/kubernetes/namespaces.go
Outdated
|
||
// DeleteNamespace will delete the namespace by the namespace name | ||
func (kc *KubeCtl) DeleteNamespace(name string) error { | ||
deletePolicy := metav1.DeletePropagationBackground |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need DeletePropagationBackground option here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I referred to https://github.com/kubernetes/kubernetes/blob/master/pkg/controller/namespace/deletion/namespaced_resources_deleter.go#L340-L344
IMO, maybe it's good to need?
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should use Foreground waiting for all resource to be killed. see https://godoc.org/k8s.io/apimachinery/pkg/apis/meta/v1#DeletionPropagation
The object exists in the key-value store until the garbage collector
deletes all the dependents whose ownerReference.blockOwnerDeletion=true
from the key-value store. API sever will put the "foregroundDeletion"
finalizer on the object, and sets its deletionTimestamp. This policy is
cascading, i.e., the dependents will be deleted with Foreground.
src/kubernetes/namespaces.go
Outdated
|
||
// DeleteNamespace will delete the namespace by the namespace name | ||
func (kc *KubeCtl) DeleteNamespace(name string) error { | ||
deletePolicy := metav1.DeletePropagationBackground |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should use Foreground waiting for all resource to be killed. see https://godoc.org/k8s.io/apimachinery/pkg/apis/meta/v1#DeletionPropagation
The object exists in the key-value store until the garbage collector
deletes all the dependents whose ownerReference.blockOwnerDeletion=true
from the key-value store. API sever will put the "foregroundDeletion"
finalizer on the object, and sets its deletionTimestamp. This policy is
cascading, i.e., the dependents will be deleted with Foreground.
src/server/handler_namespace.go
Outdated
|
||
if err := namespace.CreateNamespace(sp, &n); err != nil { | ||
if errors.IsAlreadyExists(err) { | ||
response.Conflict(req.Request, resp.ResponseWriter, fmt.Errorf("Namespace Name: %s already existed", n.Name)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Namespace: %s already existed
src/server/handler_namespace.go
Outdated
} | ||
|
||
if err := namespace.DeleteNamespace(sp, &n); err != nil { | ||
if errors.IsAlreadyExists(err) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if errors.IsNotFound(err) {
7fe5b98
to
b934625
Compare
@sufuf3 Please add namespace api usage in API.md |
To support CRUD of namespace, update src/server/route.go & add newNamespaceService.
Ref: https://raw.githubusercontent.com/kubernetes/website/master/content/en/examples/admin/namespace-dev.json ``` { "kind": "Namespace", "apiVersion": "v1", "metadata": { "name": "development", "labels": { "name": "development" } } } ```
Use Foreground waiting for all resource to be killed. Ref: - https://kubernetes.io/docs/concepts/workloads/controllers/garbage-collection/#controlling-how-the-garbage-collector-deletes-dependents - https://godoc.org/k8s.io/apimachinery/pkg/apis/meta/v1#DeletionPropagation
b934625
to
77e6bf7
Compare
@John-Lin I added namespace api usage in API.md and modified the files. |
} | ||
``` | ||
|
||
Response Data: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
response data should be the namespace entity not create success message
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copied from service, sorry that I forgot to change the response data.
Updated it.
77e6bf7
to
76d3196
Compare
src/namespace/namespace.go
Outdated
return err | ||
} | ||
|
||
// DeleteNamespace willl delete namespace |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
小錯字 will
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我修了
I finished Namespace CRUD, please help me review this PR.
Thank you.