Skip to content

Commit

Permalink
Store ns in db (#2698)
Browse files Browse the repository at this point in the history
* initial

* store the ns

* update namespace mapping

* add comments to check reference exist func
  • Loading branch information
gaoning777 authored and k8s-ci-robot committed Dec 5, 2019
1 parent 5f17ecd commit a68feed
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
20 changes: 9 additions & 11 deletions backend/src/apiserver/resource/model_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,17 +200,15 @@ func (r *ResourceManager) toModelResourceReferences(
return nil, util.Wrap(err, "Failed to find the referred resource")
}
//TODO(gaoning777) further investigation: Is the plain namespace a good option? maybe uuid for distinctness even with namespace deletion/recreation.
if apiRef.Key.Type != api.ResourceType_NAMESPACE {
modelRef := &model.ResourceReference{
ResourceUUID: resourceId,
ResourceType: resourceType,
ReferenceUUID: apiRef.Key.Id,
ReferenceName: referenceName,
ReferenceType: modelReferenceType,
Relationship: modelRelationship,
}
modelRefs = append(modelRefs, modelRef)
}
modelRef := &model.ResourceReference{
ResourceUUID: resourceId,
ResourceType: resourceType,
ReferenceUUID: apiRef.Key.Id,
ReferenceName: referenceName,
ReferenceType: modelReferenceType,
Relationship: modelRelationship,
}
modelRefs = append(modelRefs, modelRef)
}
return modelRefs, nil
}
Expand Down
2 changes: 1 addition & 1 deletion backend/src/apiserver/resource/model_converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func TestToModelResourceReferences_NamespaceRef(t *testing.T) {
{Key: &api.ResourceKey{Type: api.ResourceType_NAMESPACE, Id: "e1"}, Relationship: api.Relationship_OWNER},
})
assert.Nil(t, err)
assert.Equal(t, 0, len(modelRefs))
assert.Equal(t, 1, len(modelRefs))
}

func TestToModelResourceReferences_UnknownRelationship(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions backend/src/apiserver/server/api_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ func toApiResourceType(modelType common.ResourceType) api.ResourceType {
return api.ResourceType_JOB
case common.PipelineVersion:
return api.ResourceType_PIPELINE_VERSION
case common.Namespace:
return api.ResourceType_NAMESPACE
default:
return api.ResourceType_UNKNOWN_RESOURCE_TYPE
}
Expand Down
4 changes: 4 additions & 0 deletions backend/src/apiserver/storage/resource_reference_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ func (s *ResourceReferenceStore) checkReferenceExist(tx *sql.Tx, referenceId str
selectBuilder = sq.Select("1").From("experiments").Where(sq.Eq{"uuid": referenceId})
case common.PipelineVersion:
selectBuilder = sq.Select("1").From("pipeline_versions").Where(sq.Eq{"uuid": referenceId})
case common.Namespace:
// This function is called to check the data validity when the data are transformed according to the DB schema.
// Since there is not a separate table to store the namespace data, thus always returning true.
return true
default:
return false
}
Expand Down

0 comments on commit a68feed

Please sign in to comment.