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

[Task] Add namespace crud #227

Merged
merged 10 commits into from
Aug 14, 2018
Merged

[Task] Add namespace crud #227

merged 10 commits into from
Aug 14, 2018

Conversation

sufuf3
Copy link
Contributor

@sufuf3 sufuf3 commented Aug 8, 2018

I finished Namespace CRUD, please help me review this PR.
Thank you.

@sufuf3 sufuf3 force-pushed the sufuf3/namespace-crud branch 4 times, most recently from 0e15586 to 647745b Compare August 8, 2018 09:20
@sufuf3 sufuf3 changed the title [WIP] Add namespace crud Add namespace crud Aug 8, 2018
@sufuf3 sufuf3 force-pushed the sufuf3/namespace-crud branch from 647745b to b14d505 Compare August 8, 2018 09:30
@codecov-io
Copy link

codecov-io commented Aug 8, 2018

Codecov Report

Merging #227 into develop will decrease coverage by 0.25%.
The diff coverage is 73.75%.

Impacted file tree graph

@@             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
Impacted Files Coverage Δ
src/namespace/namespace.go 100% <100%> (ø)
src/server/handler_namespace.go 68.51% <68.51%> (ø)
src/kubernetes/namespaces.go 86.66% <86.66%> (ø)
src/server/route.go 83.67% <88.88%> (+0.52%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 08742c4...6936c7d. Read the comment docs.


// the const for NamespaceCollectionName
const (
NamespaceCollectionName string = "namespace"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

namespaces

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"`
Copy link
Contributor

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


// DeleteNamespace will delete the namespace by the namespace name
func (kc *KubeCtl) DeleteNamespace(name string) error {
deletePolicy := metav1.DeletePropagationBackground
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@John-Lin John-Lin Aug 9, 2018

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.


// DeleteNamespace will delete the namespace by the namespace name
func (kc *KubeCtl) DeleteNamespace(name string) error {
deletePolicy := metav1.DeletePropagationBackground
Copy link
Contributor

@John-Lin John-Lin Aug 9, 2018

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.


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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Namespace: %s already existed

}

if err := namespace.DeleteNamespace(sp, &n); err != nil {
if errors.IsAlreadyExists(err) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if errors.IsNotFound(err) {

@sufuf3 sufuf3 force-pushed the sufuf3/namespace-crud branch 10 times, most recently from 7fe5b98 to b934625 Compare August 13, 2018 05:05
@John-Lin
Copy link
Contributor

@sufuf3 Please add namespace api usage in API.md

sufuf3 added 3 commits August 13, 2018 22:15
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"
    }
  }
}
```
@sufuf3 sufuf3 force-pushed the sufuf3/namespace-crud branch from b934625 to 77e6bf7 Compare August 13, 2018 14:25
@sufuf3 sufuf3 requested a review from John-Lin August 13, 2018 14:35
@sufuf3
Copy link
Contributor Author

sufuf3 commented Aug 13, 2018

@John-Lin I added namespace api usage in API.md and modified the files.
Please help me review this PR. Thank you.

}
```

Response Data:
Copy link
Contributor

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

Copy link
Contributor Author

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.

@sufuf3 sufuf3 force-pushed the sufuf3/namespace-crud branch from 77e6bf7 to 76d3196 Compare August 13, 2018 16:19
return err
}

// DeleteNamespace willl delete namespace
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

小錯字 will

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我修了

@John-Lin John-Lin changed the title Add namespace crud [Task] Add namespace crud Aug 14, 2018
@John-Lin John-Lin merged commit 0342e92 into develop Aug 14, 2018
@sufuf3 sufuf3 deleted the sufuf3/namespace-crud branch August 14, 2018 07:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants