Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dynamo
Commits
5ddc7f7d
"autonomous_driving/vscode:/vscode.git/clone" did not exist on "b64d9ca3000f4753e26d3b8c8fec05052114a126"
Commit
5ddc7f7d
authored
Mar 04, 2025
by
Maksim Khadkevich
Committed by
GitHub
Mar 04, 2025
Browse files
feat: moved compoundAI operator, APIserver, and examples (#10)
parent
14ce7e03
Changes
239
Show whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
1350 additions
and
0 deletions
+1350
-0
deploy/compoundai/api-server/api/controllers/organization.go
deploy/compoundai/api-server/api/controllers/organization.go
+108
-0
deploy/compoundai/api-server/api/controllers/organization_member.go
...poundai/api-server/api/controllers/organization_member.go
+43
-0
deploy/compoundai/api-server/api/controllers/proxy.go
deploy/compoundai/api-server/api/controllers/proxy.go
+43
-0
deploy/compoundai/api-server/api/controllers/user.go
deploy/compoundai/api-server/api/controllers/user.go
+34
-0
deploy/compoundai/api-server/api/controllers/version.go
deploy/compoundai/api-server/api/controllers/version.go
+43
-0
deploy/compoundai/api-server/api/converters/base.go
deploy/compoundai/api-server/api/converters/base.go
+39
-0
deploy/compoundai/api-server/api/converters/cluster.go
deploy/compoundai/api-server/api/converters/cluster.go
+80
-0
deploy/compoundai/api-server/api/converters/compound_component.go
...ompoundai/api-server/api/converters/compound_component.go
+68
-0
deploy/compoundai/api-server/api/converters/deployment.go
deploy/compoundai/api-server/api/converters/deployment.go
+156
-0
deploy/compoundai/api-server/api/converters/deployment_revision.go
...mpoundai/api-server/api/converters/deployment_revision.go
+95
-0
deploy/compoundai/api-server/api/converters/deployment_target.go
...compoundai/api-server/api/converters/deployment_target.go
+85
-0
deploy/compoundai/api-server/api/converters/resource.go
deploy/compoundai/api-server/api/converters/resource.go
+32
-0
deploy/compoundai/api-server/api/crds/base.go
deploy/compoundai/api-server/api/crds/base.go
+47
-0
deploy/compoundai/api-server/api/crds/compoundai_nim_deployment.go
...mpoundai/api-server/api/crds/compoundai_nim_deployment.go
+83
-0
deploy/compoundai/api-server/api/crds/compoundai_nim_request.go
.../compoundai/api-server/api/crds/compoundai_nim_request.go
+45
-0
deploy/compoundai/api-server/api/crds/consts.go
deploy/compoundai/api-server/api/crds/consts.go
+27
-0
deploy/compoundai/api-server/api/database/database.go
deploy/compoundai/api-server/api/database/database.go
+168
-0
deploy/compoundai/api-server/api/main.go
deploy/compoundai/api-server/api/main.go
+28
-0
deploy/compoundai/api-server/api/mocks/mock.go
deploy/compoundai/api-server/api/mocks/mock.go
+75
-0
deploy/compoundai/api-server/api/models/associate.go
deploy/compoundai/api-server/api/models/associate.go
+51
-0
No files found.
deploy/compoundai/api-server/api/controllers/organization.go
0 → 100644
View file @
5ddc7f7d
/*
* SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
controllers
import
(
"context"
"github.com/dynemo-ai/dynemo/deploy/compoundai/api-server/api/common/consts"
"github.com/dynemo-ai/dynemo/deploy/compoundai/api-server/api/converters"
"github.com/dynemo-ai/dynemo/deploy/compoundai/api-server/api/mocks"
"github.com/dynemo-ai/dynemo/deploy/compoundai/api-server/api/schemas"
"github.com/gin-gonic/gin"
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
)
type
organizationController
struct
{}
var
OrganizationController
=
organizationController
{}
const
CurrentOrganizationKey
=
"currentOrganization"
const
CurrentOrganizationIdKey
=
"currentOrganizationId"
func
GetCurrentOrganization
(
ctx
context
.
Context
)
(
*
schemas
.
OrganizationSchema
,
error
)
{
org_
:=
ctx
.
Value
(
CurrentOrganizationKey
)
if
org_
==
nil
{
return
nil
,
consts
.
ErrNotFound
}
org
,
ok
:=
org_
.
(
*
schemas
.
OrganizationSchema
)
if
!
ok
{
return
nil
,
errors
.
New
(
"current organization is not a organization"
)
}
return
org
,
nil
}
func
(
c
*
organizationController
)
Create
(
ctx
*
gin
.
Context
)
{
ctx
.
JSON
(
501
,
gin
.
H
{
"error"
:
"not supported."
})
}
func
(
c
*
organizationController
)
Update
(
ctx
*
gin
.
Context
)
{
ctx
.
JSON
(
501
,
gin
.
H
{
"error"
:
"not supported."
})
}
func
(
c
*
organizationController
)
Get
(
ctx
*
gin
.
Context
)
{
organization
,
err
:=
GetCurrentOrganization
(
ctx
)
if
err
!=
nil
{
ctx
.
JSON
(
400
,
gin
.
H
{
"error"
:
err
.
Error
()})
return
}
ctx
.
JSON
(
200
,
organization
)
}
func
(
c
*
organizationController
)
GetMajorCluster
(
ctx
*
gin
.
Context
)
{
cluster
,
err
:=
ClusterController
.
GetCluster
(
ctx
,
"default"
)
if
err
!=
nil
{
log
.
Info
()
.
Msgf
(
"Failed to get default cluster: %s"
,
err
.
Error
())
ctx
.
JSON
(
404
,
gin
.
H
{
"error"
:
err
.
Error
()})
return
}
ctx
.
JSON
(
200
,
converters
.
ToClusterFullSchema
(
cluster
))
}
func
(
c
*
organizationController
)
List
(
ctx
*
gin
.
Context
)
{
var
schema
schemas
.
ListQuerySchema
if
err
:=
ctx
.
ShouldBindQuery
(
&
schema
);
err
!=
nil
{
ctx
.
JSON
(
400
,
gin
.
H
{
"error"
:
err
.
Error
()})
return
}
organizationSchemas
:=
[]
*
schemas
.
OrganizationSchema
{
mocks
.
DefaultOrg
()}
organizationListSchema
:=
schemas
.
OrganizationListSchema
{
BaseListSchema
:
schemas
.
BaseListSchema
{
Total
:
1
,
Start
:
schema
.
Start
,
Count
:
schema
.
Count
,
},
Items
:
organizationSchemas
,
}
ctx
.
JSON
(
200
,
organizationListSchema
)
}
func
(
c
*
organizationController
)
ListEventOperationNames
(
ctx
*
gin
.
Context
)
{
ctx
.
JSON
(
200
,
[]
string
{})
}
func
(
c
*
organizationController
)
ListEvents
(
ctx
*
gin
.
Context
)
{
ctx
.
JSON
(
200
,
schemas
.
EventListSchema
{
Items
:
[]
*
schemas
.
EventSchema
{},
})
}
deploy/compoundai/api-server/api/controllers/organization_member.go
0 → 100644
View file @
5ddc7f7d
/*
* SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
controllers
import
(
"github.com/dynemo-ai/dynemo/deploy/compoundai/api-server/api/mocks"
"github.com/dynemo-ai/dynemo/deploy/compoundai/api-server/api/schemas"
"github.com/gin-gonic/gin"
)
type
organizationMemberController
struct
{
organizationController
}
var
OrganizationMemberController
=
organizationMemberController
{}
func
(
c
*
organizationMemberController
)
Create
(
ctx
*
gin
.
Context
)
{
ctx
.
JSON
(
501
,
gin
.
H
{
"error"
:
"not supported."
})
}
func
(
c
*
organizationMemberController
)
List
(
ctx
*
gin
.
Context
)
{
organizationMemberSchemaList
:=
[]
*
schemas
.
OrganizationMemberSchema
{
mocks
.
DefaultOrgMember
()}
ctx
.
JSON
(
200
,
organizationMemberSchemaList
)
}
func
(
c
*
organizationMemberController
)
Delete
(
ctx
*
gin
.
Context
)
{
ctx
.
JSON
(
501
,
gin
.
H
{
"error"
:
"not supported."
})
}
deploy/compoundai/api-server/api/controllers/proxy.go
0 → 100644
View file @
5ddc7f7d
/*
* SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
controllers
import
(
"net/http"
"net/http/httputil"
"github.com/dynemo-ai/dynemo/deploy/compoundai/api-server/api/common/env"
"github.com/gin-gonic/gin"
)
type
proxyController
struct
{}
var
ProxyController
=
proxyController
{}
func
(
*
proxyController
)
ReverseProxy
(
ctx
*
gin
.
Context
)
{
ndsUrl
:=
env
.
GetNdsHost
()
director
:=
func
(
req
*
http
.
Request
)
{
r
:=
ctx
.
Request
req
.
URL
.
Scheme
=
"http"
req
.
URL
.
Host
=
ndsUrl
req
.
Header
=
r
.
Header
.
Clone
()
}
proxy
:=
&
httputil
.
ReverseProxy
{
Director
:
director
}
proxy
.
ServeHTTP
(
ctx
.
Writer
,
ctx
.
Request
)
}
deploy/compoundai/api-server/api/controllers/user.go
0 → 100644
View file @
5ddc7f7d
/*
* SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
controllers
import
(
"github.com/dynemo-ai/dynemo/deploy/compoundai/api-server/api/mocks"
"github.com/gin-gonic/gin"
)
type
userController
struct
{}
const
CurrentUserIdKey
=
"currentUserId"
var
UserController
=
userController
{}
func
(
c
*
userController
)
GetDefaultUser
(
ctx
*
gin
.
Context
)
{
user
:=
mocks
.
DefaultUser
()
ctx
.
JSON
(
200
,
user
)
}
deploy/compoundai/api-server/api/controllers/version.go
0 → 100644
View file @
5ddc7f7d
/*
* SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
controllers
import
(
"github.com/dynemo-ai/dynemo/deploy/compoundai/api-server/api/schemas"
"github.com/gin-gonic/gin"
)
var
(
Version
=
"0.0.1"
GitCommit
=
"HEAD"
BuildDate
=
"1970-01-01T00:00:00Z"
)
type
versionController
struct
{}
var
VersionController
=
versionController
{}
func
(
c
*
versionController
)
Get
(
ctx
*
gin
.
Context
)
{
versionSchema
:=
&
schemas
.
VersionSchema
{
Version
:
Version
,
GitCommit
:
GitCommit
,
BuildDate
:
BuildDate
,
}
ctx
.
JSON
(
200
,
versionSchema
)
}
deploy/compoundai/api-server/api/converters/base.go
0 → 100644
View file @
5ddc7f7d
/*
* SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
converters
import
(
"time"
"github.com/dynemo-ai/dynemo/deploy/compoundai/api-server/api/models"
"github.com/dynemo-ai/dynemo/deploy/compoundai/api-server/api/schemas"
)
func
ToBaseSchema
(
base
models
.
BaseModel
)
schemas
.
BaseSchema
{
var
deletedAt
*
time
.
Time
deletedAt_
:=
base
.
GetDeletedAt
()
if
deletedAt_
.
Valid
{
deletedAt
=
&
deletedAt_
.
Time
}
return
schemas
.
BaseSchema
{
Uid
:
base
.
GetUid
(),
CreatedAt
:
base
.
GetCreatedAt
(),
UpdatedAt
:
base
.
GetUpdatedAt
(),
DeletedAt
:
deletedAt
,
}
}
deploy/compoundai/api-server/api/converters/cluster.go
0 → 100644
View file @
5ddc7f7d
/*
* SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
converters
import
(
"github.com/dynemo-ai/dynemo/deploy/compoundai/api-server/api/mocks"
"github.com/dynemo-ai/dynemo/deploy/compoundai/api-server/api/models"
"github.com/dynemo-ai/dynemo/deploy/compoundai/api-server/api/schemas"
"github.com/dynemo-ai/dynemo/deploy/compoundai/api-server/api/schemasv2"
)
func
ToClusterSchemaList
(
clusters
[]
*
models
.
Cluster
)
[]
*
schemas
.
ClusterSchema
{
clusterSchemas
:=
make
([]
*
schemas
.
ClusterSchema
,
0
)
for
_
,
cluster
:=
range
clusters
{
clusterSchemas
=
append
(
clusterSchemas
,
ToClusterSchema
(
cluster
))
}
return
clusterSchemas
}
func
ToClusterSchema
(
cluster
*
models
.
Cluster
)
*
schemas
.
ClusterSchema
{
return
&
schemas
.
ClusterSchema
{
Creator
:
mocks
.
DefaultUser
(),
Description
:
cluster
.
Description
,
ResourceSchema
:
schemas
.
ResourceSchema
{
Name
:
cluster
.
Name
,
ResourceType
:
schemas
.
ResourceTypeCluster
,
BaseSchema
:
schemas
.
BaseSchema
{
Uid
:
cluster
.
GetUid
(),
CreatedAt
:
cluster
.
CreatedAt
,
UpdatedAt
:
cluster
.
UpdatedAt
,
DeletedAt
:
&
cluster
.
DeletedAt
.
Time
,
},
},
}
}
func
ToClusterFullSchema
(
cluster
*
models
.
Cluster
)
*
schemas
.
ClusterFullSchema
{
clusterSchema
:=
ToClusterSchema
(
cluster
)
return
&
schemas
.
ClusterFullSchema
{
ClusterSchema
:
*
clusterSchema
,
KubeConfig
:
&
cluster
.
KubeConfig
,
Organization
:
mocks
.
DefaultOrg
(),
}
}
func
ToClusterSchemaV2
(
cluster
*
models
.
Cluster
,
creator
*
schemas
.
UserSchema
)
*
schemasv2
.
ClusterSchema
{
return
&
schemasv2
.
ClusterSchema
{
Description
:
cluster
.
Description
,
OrganizationName
:
"nvidia"
,
Creator
:
creator
,
ResourceSchema
:
schemas
.
ResourceSchema
{
Name
:
cluster
.
Name
,
Labels
:
[]
schemas
.
LabelItemSchema
{},
BaseSchema
:
schemas
.
BaseSchema
{
Uid
:
cluster
.
Resource
.
BaseModel
.
GetUid
(),
CreatedAt
:
cluster
.
Resource
.
BaseModel
.
CreatedAt
,
UpdatedAt
:
cluster
.
Resource
.
BaseModel
.
UpdatedAt
,
DeletedAt
:
nil
,
// Can assume that this is nil during creation
},
},
}
}
deploy/compoundai/api-server/api/converters/compound_component.go
0 → 100644
View file @
5ddc7f7d
/*
* SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
converters
import
(
"context"
"github.com/dynemo-ai/dynemo/deploy/compoundai/api-server/api/models"
"github.com/dynemo-ai/dynemo/deploy/compoundai/api-server/api/schemas"
"github.com/dynemo-ai/dynemo/deploy/compoundai/api-server/api/services"
"github.com/pkg/errors"
)
func
ToCompoundComponentSchema
(
ctx
context
.
Context
,
compoundComponent
*
models
.
CompoundComponent
)
(
*
schemas
.
CompoundComponentSchema
,
error
)
{
if
compoundComponent
==
nil
{
return
nil
,
nil
}
ss
,
err
:=
ToCompoundComponentSchemas
(
ctx
,
[]
*
models
.
CompoundComponent
{
compoundComponent
})
if
err
!=
nil
{
return
nil
,
errors
.
Wrap
(
err
,
"ToCompoundComponentSchemas"
)
}
return
ss
[
0
],
nil
}
func
ToCompoundComponentSchemas
(
ctx
context
.
Context
,
compoundComponents
[]
*
models
.
CompoundComponent
)
([]
*
schemas
.
CompoundComponentSchema
,
error
)
{
resourceSchemasMap
:=
make
(
map
[
string
]
*
schemas
.
ResourceSchema
,
len
(
compoundComponents
))
for
_
,
component
:=
range
compoundComponents
{
resourceSchemasMap
[
component
.
GetUid
()]
=
ToResourceSchema
(
&
component
.
Resource
,
component
.
GetResourceType
())
}
res
:=
make
([]
*
schemas
.
CompoundComponentSchema
,
0
,
len
(
compoundComponents
))
for
_
,
compoundComponent
:=
range
compoundComponents
{
cluster
,
err
:=
services
.
ClusterService
.
Get
(
ctx
,
compoundComponent
.
ClusterId
)
if
err
!=
nil
{
return
nil
,
err
}
clusterSchema
:=
ToClusterFullSchema
(
cluster
)
resourceSchema
,
ok
:=
resourceSchemasMap
[
compoundComponent
.
GetUid
()]
if
!
ok
{
return
nil
,
errors
.
Errorf
(
"resource schema not found for CompoundComponent %s"
,
compoundComponent
.
GetUid
())
}
res
=
append
(
res
,
&
schemas
.
CompoundComponentSchema
{
ResourceSchema
:
*
resourceSchema
,
Cluster
:
clusterSchema
,
Manifest
:
compoundComponent
.
Manifest
,
Version
:
compoundComponent
.
Version
,
KubeNamespace
:
compoundComponent
.
KubeNamespace
,
LatestHeartbeatAt
:
compoundComponent
.
LatestHeartbeatAt
,
LatestInstalledAt
:
compoundComponent
.
LatestInstalledAt
,
})
}
return
res
,
nil
}
deploy/compoundai/api-server/api/converters/deployment.go
0 → 100644
View file @
5ddc7f7d
/*
* SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
converters
import
(
"context"
"fmt"
"github.com/dynemo-ai/dynemo/deploy/compoundai/api-server/api/mocks"
"github.com/dynemo-ai/dynemo/deploy/compoundai/api-server/api/models"
"github.com/dynemo-ai/dynemo/deploy/compoundai/api-server/api/schemas"
"github.com/dynemo-ai/dynemo/deploy/compoundai/api-server/api/schemasv2"
"github.com/dynemo-ai/dynemo/deploy/compoundai/api-server/api/services"
)
func
ToDeploymentSchema
(
ctx
context
.
Context
,
deployment
*
models
.
Deployment
)
(
*
schemas
.
DeploymentSchema
,
error
)
{
if
deployment
==
nil
{
return
nil
,
nil
}
ss
,
err
:=
ToDeploymentSchemas
(
ctx
,
[]
*
models
.
Deployment
{
deployment
})
if
err
!=
nil
{
return
nil
,
err
}
return
ss
[
0
],
nil
}
func
ToDeploymentSchemas
(
ctx
context
.
Context
,
deployments
[]
*
models
.
Deployment
)
([]
*
schemas
.
DeploymentSchema
,
error
)
{
status_
:=
schemas
.
DeploymentRevisionStatusActive
deploymentIds
:=
make
([]
uint
,
0
,
len
(
deployments
))
for
_
,
deployment
:=
range
deployments
{
deploymentIds
=
append
(
deploymentIds
,
deployment
.
ID
)
}
deploymentRevisions
,
_
,
err
:=
services
.
DeploymentRevisionService
.
List
(
ctx
,
services
.
ListDeploymentRevisionOption
{
DeploymentIds
:
&
deploymentIds
,
Status
:
&
status_
,
})
if
err
!=
nil
{
return
nil
,
err
}
deploymentIdToDeploymentRevisionUid
:=
make
(
map
[
uint
]
string
)
for
_
,
deploymentRevision
:=
range
deploymentRevisions
{
deploymentIdToDeploymentRevisionUid
[
deploymentRevision
.
DeploymentId
]
=
deploymentRevision
.
GetUid
()
}
deploymentRevisionSchemas
,
err
:=
ToDeploymentRevisionSchemas
(
ctx
,
deploymentRevisions
)
if
err
!=
nil
{
return
nil
,
err
}
deploymentRevisionSchemasMap
:=
make
(
map
[
string
]
*
schemas
.
DeploymentRevisionSchema
)
for
_
,
deploymentRevisionSchema
:=
range
deploymentRevisionSchemas
{
deploymentRevisionSchemasMap
[
deploymentRevisionSchema
.
Uid
]
=
deploymentRevisionSchema
}
resourceSchemaMap
:=
make
(
map
[
string
]
*
schemas
.
ResourceSchema
,
len
(
deployments
))
for
_
,
deployment
:=
range
deployments
{
resourceSchemaMap
[
deployment
.
GetUid
()]
=
ToResourceSchema
(
&
deployment
.
Resource
,
deployment
.
GetResourceType
())
}
res
:=
make
([]
*
schemas
.
DeploymentSchema
,
0
,
len
(
deployments
))
for
_
,
deployment
:=
range
deployments
{
deploymentRevisionUid
:=
deploymentIdToDeploymentRevisionUid
[
deployment
.
ID
]
deploymentRevisionSchema
:=
deploymentRevisionSchemasMap
[
deploymentRevisionUid
]
creatorSchema
:=
mocks
.
DefaultUser
()
cluster
,
err
:=
services
.
ClusterService
.
Get
(
ctx
,
deployment
.
ClusterId
)
if
err
!=
nil
{
return
nil
,
err
}
clusterSchema
:=
ToClusterFullSchema
(
cluster
)
urls
:=
make
([]
string
,
0
)
// TODO: implement get ingress urls...
// urls, err := services.DeploymentService.GetURLs(ctx, deployment)
// if err != nil {
// return nil, err
// }
resourceSchema
,
ok
:=
resourceSchemaMap
[
deployment
.
GetUid
()]
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"resourceSchema not found for deployment %s"
,
deployment
.
GetUid
())
}
res
=
append
(
res
,
&
schemas
.
DeploymentSchema
{
ResourceSchema
:
*
resourceSchema
,
Creator
:
creatorSchema
,
Cluster
:
clusterSchema
,
Status
:
deployment
.
Status
,
LatestRevision
:
deploymentRevisionSchema
,
URLs
:
urls
,
KubeNamespace
:
deployment
.
KubeNamespace
,
})
}
return
res
,
nil
}
func
ToDeploymentSchemaV2
(
ctx
context
.
Context
,
cluster
*
models
.
Cluster
,
deployment
*
models
.
Deployment
,
creator
*
schemas
.
UserSchema
)
(
*
schemasv2
.
DeploymentSchema
,
error
)
{
clusterSchema
:=
ToClusterSchemaV2
(
cluster
,
creator
)
status
:=
schemas
.
DeploymentRevisionStatusActive
deploymentRevisionListOpts
:=
services
.
ListDeploymentRevisionOption
{
DeploymentId
:
&
deployment
.
ID
,
Status
:
&
status
,
}
deploymentRevisions
,
total
,
err
:=
services
.
DeploymentRevisionService
.
List
(
ctx
,
deploymentRevisionListOpts
)
if
err
!=
nil
{
return
nil
,
err
}
var
revision
*
models
.
DeploymentRevision
if
total
>
0
{
revision
=
deploymentRevisions
[
0
]
}
revisionSchema
,
err
:=
ToDeploymentRevisionSchema
(
ctx
,
revision
)
if
err
!=
nil
{
return
nil
,
err
}
return
&
schemasv2
.
DeploymentSchema
{
ResourceSchema
:
schemas
.
ResourceSchema
{
Name
:
deployment
.
Resource
.
Name
,
Labels
:
[]
schemas
.
LabelItemSchema
{},
ResourceType
:
deployment
.
GetResourceType
(),
BaseSchema
:
schemas
.
BaseSchema
{
Uid
:
deployment
.
Resource
.
BaseModel
.
GetUid
(),
CreatedAt
:
deployment
.
Resource
.
BaseModel
.
CreatedAt
,
UpdatedAt
:
deployment
.
Resource
.
BaseModel
.
UpdatedAt
,
DeletedAt
:
nil
,
// Can assume that this is nil during creation
},
},
// Assuming ResourceSchema can be copied directly
Creator
:
creator
,
Cluster
:
clusterSchema
,
Status
:
deployment
.
Status
,
URLs
:
[]
string
{},
LatestRevision
:
revisionSchema
,
KubeNamespace
:
deployment
.
KubeNamespace
,
},
nil
}
deploy/compoundai/api-server/api/converters/deployment_revision.go
0 → 100644
View file @
5ddc7f7d
/*
* SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
converters
import
(
"context"
"fmt"
"github.com/dynemo-ai/dynemo/deploy/compoundai/api-server/api/mocks"
"github.com/dynemo-ai/dynemo/deploy/compoundai/api-server/api/models"
"github.com/dynemo-ai/dynemo/deploy/compoundai/api-server/api/schemas"
"github.com/dynemo-ai/dynemo/deploy/compoundai/api-server/api/services"
)
func
ToDeploymentRevisionSchema
(
ctx
context
.
Context
,
deploymentRevision
*
models
.
DeploymentRevision
)
(
*
schemas
.
DeploymentRevisionSchema
,
error
)
{
if
deploymentRevision
==
nil
{
return
nil
,
nil
}
ss
,
err
:=
ToDeploymentRevisionSchemas
(
ctx
,
[]
*
models
.
DeploymentRevision
{
deploymentRevision
})
if
err
!=
nil
{
return
nil
,
err
}
return
ss
[
0
],
nil
}
func
ToDeploymentRevisionSchemas
(
ctx
context
.
Context
,
deploymentRevisions
[]
*
models
.
DeploymentRevision
)
([]
*
schemas
.
DeploymentRevisionSchema
,
error
)
{
deploymentRevisionIds
:=
make
([]
uint
,
0
,
len
(
deploymentRevisions
))
for
_
,
deploymentRevision
:=
range
deploymentRevisions
{
deploymentRevisionIds
=
append
(
deploymentRevisionIds
,
deploymentRevision
.
ID
)
}
deploymentTargets
,
_
,
err
:=
services
.
DeploymentTargetService
.
List
(
ctx
,
services
.
ListDeploymentTargetOption
{
DeploymentRevisionIds
:
&
deploymentRevisionIds
,
})
if
err
!=
nil
{
return
nil
,
err
}
deploymentTargetsMapping
:=
make
(
map
[
uint
][]
*
models
.
DeploymentTarget
)
for
_
,
deploymentTarget
:=
range
deploymentTargets
{
deploymentTargets
,
ok
:=
deploymentTargetsMapping
[
deploymentTarget
.
DeploymentRevisionId
]
if
!
ok
{
deploymentTargets
=
make
([]
*
models
.
DeploymentTarget
,
0
)
}
deploymentTargets
=
append
(
deploymentTargets
,
deploymentTarget
)
deploymentTargetsMapping
[
deploymentTarget
.
DeploymentRevisionId
]
=
deploymentTargets
}
resourceSchemasMap
:=
make
(
map
[
string
]
*
schemas
.
ResourceSchema
,
len
(
deploymentRevisions
))
for
_
,
revision
:=
range
deploymentRevisions
{
resourceSchemasMap
[
revision
.
GetUid
()]
=
ToResourceSchema
(
revisionToResource
(
revision
),
revision
.
GetResourceType
())
}
res
:=
make
([]
*
schemas
.
DeploymentRevisionSchema
,
0
,
len
(
deploymentRevisions
))
for
_
,
deploymentRevision
:=
range
deploymentRevisions
{
creatorSchema
:=
mocks
.
DefaultUser
()
deploymentTargets
:=
deploymentTargetsMapping
[
deploymentRevision
.
ID
]
deploymentTargetSchemas
,
err
:=
ToDeploymentTargetSchemas
(
ctx
,
deploymentTargets
)
if
err
!=
nil
{
return
nil
,
err
}
resourceSchema
,
ok
:=
resourceSchemasMap
[
deploymentRevision
.
GetUid
()]
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"resourceSchema not found for deploymentRevision %s"
,
deploymentRevision
.
GetUid
())
}
res
=
append
(
res
,
&
schemas
.
DeploymentRevisionSchema
{
ResourceSchema
:
*
resourceSchema
,
Creator
:
creatorSchema
,
Status
:
deploymentRevision
.
Status
,
Targets
:
deploymentTargetSchemas
,
})
}
return
res
,
nil
}
func
revisionToResource
(
deploymentTarget
*
models
.
DeploymentRevision
)
*
models
.
Resource
{
return
&
models
.
Resource
{
BaseModel
:
deploymentTarget
.
BaseModel
,
Name
:
deploymentTarget
.
GetUid
(),
}
}
deploy/compoundai/api-server/api/converters/deployment_target.go
0 → 100644
View file @
5ddc7f7d
/*
* SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
converters
import
(
"context"
"fmt"
"strings"
"github.com/dynemo-ai/dynemo/deploy/compoundai/api-server/api/mocks"
"github.com/dynemo-ai/dynemo/deploy/compoundai/api-server/api/models"
"github.com/dynemo-ai/dynemo/deploy/compoundai/api-server/api/schemas"
"github.com/dynemo-ai/dynemo/deploy/compoundai/api-server/api/services"
"github.com/pkg/errors"
)
func
ToDeploymentTargetSchema
(
ctx
context
.
Context
,
deploymentTarget
*
models
.
DeploymentTarget
)
(
*
schemas
.
DeploymentTargetSchema
,
error
)
{
if
deploymentTarget
==
nil
{
return
nil
,
nil
}
ss
,
err
:=
ToDeploymentTargetSchemas
(
ctx
,
[]
*
models
.
DeploymentTarget
{
deploymentTarget
})
if
err
!=
nil
{
return
nil
,
err
}
return
ss
[
0
],
nil
}
func
ToDeploymentTargetSchemas
(
ctx
context
.
Context
,
deploymentTargets
[]
*
models
.
DeploymentTarget
)
([]
*
schemas
.
DeploymentTargetSchema
,
error
)
{
resourceSchemasMap
:=
make
(
map
[
string
]
*
schemas
.
ResourceSchema
,
len
(
deploymentTargets
))
for
_
,
target
:=
range
deploymentTargets
{
resourceSchemasMap
[
target
.
GetUid
()]
=
ToResourceSchema
(
targetToResource
(
target
),
target
.
GetResourceType
())
}
res
:=
make
([]
*
schemas
.
DeploymentTargetSchema
,
0
,
len
(
deploymentTargets
))
for
_
,
deploymentTarget
:=
range
deploymentTargets
{
creatorSchema
:=
mocks
.
DefaultUser
()
compoundNimParts
:=
strings
.
Split
(
deploymentTarget
.
CompoundNimVersionTag
,
":"
)
if
len
(
compoundNimParts
)
!=
2
{
return
nil
,
errors
.
Errorf
(
"Invalid format for CompoundNIM version tag %s. Expected 2 parts got %d"
,
deploymentTarget
.
CompoundNimVersionTag
,
len
(
compoundNimParts
))
}
compoundNimVersionFullSchema
,
err
:=
services
.
DatastoreService
.
GetCompoundNimVersion
(
ctx
,
compoundNimParts
[
0
],
compoundNimParts
[
1
])
if
err
!=
nil
{
compoundNimVersionFullSchema
=
nil
// We shouldn't fail the request if this info is missing
}
resourceSchema
,
ok
:=
resourceSchemasMap
[
deploymentTarget
.
GetUid
()]
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"resourceSchema not found for deploymentTarget %s"
,
deploymentTarget
.
GetUid
())
}
res
=
append
(
res
,
&
schemas
.
DeploymentTargetSchema
{
ResourceSchema
:
*
resourceSchema
,
DeploymentTargetTypeSchema
:
schemas
.
DeploymentTargetTypeSchema
{
Type
:
"stable"
,
},
Creator
:
creatorSchema
,
CompoundNimVersion
:
compoundNimVersionFullSchema
,
Config
:
deploymentTarget
.
Config
,
})
}
return
res
,
nil
}
func
targetToResource
(
deploymentTarget
*
models
.
DeploymentTarget
)
*
models
.
Resource
{
return
&
models
.
Resource
{
BaseModel
:
deploymentTarget
.
BaseModel
,
Name
:
deploymentTarget
.
GetUid
(),
}
}
deploy/compoundai/api-server/api/converters/resource.go
0 → 100644
View file @
5ddc7f7d
/*
* SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
converters
import
(
"github.com/dynemo-ai/dynemo/deploy/compoundai/api-server/api/models"
"github.com/dynemo-ai/dynemo/deploy/compoundai/api-server/api/schemas"
)
func
ToResourceSchema
(
resource
*
models
.
Resource
,
resourceType
schemas
.
ResourceType
)
*
schemas
.
ResourceSchema
{
return
&
schemas
.
ResourceSchema
{
BaseSchema
:
ToBaseSchema
(
resource
.
BaseModel
),
Name
:
resource
.
Name
,
ResourceType
:
resourceType
,
Labels
:
[]
schemas
.
LabelItemSchema
{},
}
}
deploy/compoundai/api-server/api/crds/base.go
0 → 100644
View file @
5ddc7f7d
/*
* SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
crds
import
corev1
"k8s.io/api/core/v1"
type
ExtraPodMetadata
struct
{
Annotations
map
[
string
]
string
`json:"annotations,omitempty"`
Labels
map
[
string
]
string
`json:"labels,omitempty"`
}
type
ExtraPodSpec
struct
{
SchedulerName
string
`json:"schedulerName,omitempty"`
NodeSelector
map
[
string
]
string
`json:"nodeSelector,omitempty"`
Affinity
*
corev1
.
Affinity
`json:"affinity,omitempty"`
Tolerations
[]
corev1
.
Toleration
`json:"tolerations,omitempty"`
TopologySpreadConstraints
[]
corev1
.
TopologySpreadConstraint
`json:"topologySpreadConstraints,omitempty"`
Containers
[]
corev1
.
Container
`json:"containers,omitempty"`
ServiceAccountName
string
`json:"serviceAccountName,omitempty"`
}
type
ResourceItem
struct
{
CPU
string
`json:"cpu,omitempty"`
Memory
string
`json:"memory,omitempty"`
GPU
string
`json:"gpu,omitempty"`
Custom
map
[
string
]
string
`json:"custom,omitempty"`
}
type
Resources
struct
{
Requests
*
ResourceItem
`json:"requests,omitempty"`
Limits
*
ResourceItem
`json:"limits,omitempty"`
}
deploy/compoundai/api-server/api/crds/compoundai_nim_deployment.go
0 → 100644
View file @
5ddc7f7d
/*
* SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
crds
import
(
"github.com/dynemo-ai/dynemo/deploy/compoundai/api-server/api/schemas"
autoscalingv2beta2
"k8s.io/api/autoscaling/v2beta2"
corev1
"k8s.io/api/core/v1"
)
type
Autoscaling
struct
{
MinReplicas
int32
`json:"minReplicas"`
MaxReplicas
int32
`json:"maxReplicas"`
Metrics
[]
autoscalingv2beta2
.
MetricSpec
`json:"metrics,omitempty"`
Behavior
*
autoscalingv2beta2
.
HorizontalPodAutoscalerBehavior
`json:"behavior,omitempty"`
}
type
CompoundNimVersionDeploymentIngressTLSSpec
struct
{
SecretName
string
`json:"secretName,omitempty"`
}
type
CompoundNimVersionDeploymentIngressSpec
struct
{
Enabled
bool
`json:"enabled,omitempty"`
Annotations
map
[
string
]
string
`json:"annotations,omitempty"`
Labels
map
[
string
]
string
`json:"labels,omitempty"`
TLS
*
CompoundNimVersionDeploymentIngressTLSSpec
`json:"tls,omitempty"`
}
type
MonitorExporterMountSpec
struct
{
Path
string
`json:"path,omitempty"`
ReadOnly
bool
`json:"readOnly,omitempty"`
corev1
.
VolumeSource
`json:",inline"`
}
type
MonitorExporterSpec
struct
{
Enabled
bool
`json:"enabled,omitempty"`
Output
string
`json:"output,omitempty"`
Options
map
[
string
]
string
`json:"options,omitempty"`
StructureOptions
[]
corev1
.
EnvVar
`json:"structureOptions,omitempty"`
Mounts
[]
MonitorExporterMountSpec
`json:"mounts,omitempty"`
}
type
CompoundNimDeploymentData
struct
{
Annotations
map
[
string
]
string
`json:"annotations,omitempty"`
Labels
map
[
string
]
string
`json:"labels,omitempty"`
CompoundNimVersion
string
`json:"compoundAINim"`
Resources
schemas
.
Resources
`json:"resources,omitempty"`
Autoscaling
*
Autoscaling
`json:"autoscaling,omitempty"`
Envs
[]
corev1
.
EnvVar
`json:"envs,omitempty"`
ExternalServices
map
[
string
]
schemas
.
ExternalService
`json:"externalServices,omitempty"`
Ingress
CompoundNimVersionDeploymentIngressSpec
`json:"ingress,omitempty"`
MonitorExporter
*
MonitorExporterSpec
`json:"monitorExporter,omitempty"`
ExtraPodMetadata
*
ExtraPodMetadata
`json:"extraPodMetadata,omitempty"`
ExtraPodSpec
*
ExtraPodSpec
`json:"extraPodSpec,omitempty"`
LivenessProbe
*
corev1
.
Probe
`json:"livenessProbe,omitempty"`
ReadinessProbe
*
corev1
.
Probe
`json:"readinessProbe,omitempty"`
}
type
CompoundNimDeploymentConfigurationV1Alpha1
struct
{
Data
CompoundNimDeploymentData
`json:"data"`
Version
string
`json:"version"`
}
deploy/compoundai/api-server/api/crds/compoundai_nim_request.go
0 → 100644
View file @
5ddc7f7d
/*
* SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
crds
import
(
"time"
corev1
"k8s.io/api/core/v1"
)
type
CompoundNimRequestData
struct
{
CompoundNimVersionTag
string
`json:"bentoTag"`
DownloadURL
string
`json:"downloadUrl,omitempty"`
ImageBuildTimeout
*
time
.
Duration
`json:"imageBuildTimeout,omitempty"`
ImageBuilderExtraPodMetadata
*
ExtraPodMetadata
`json:"imageBuilderExtraPodMetadata,omitempty"`
ImageBuilderExtraPodSpec
*
ExtraPodSpec
`json:"imageBuilderExtraPodSpec,omitempty"`
ImageBuilderExtraContainerEnv
[]
corev1
.
EnvVar
`json:"imageBuilderExtraContainerEnv,omitempty"`
ImageBuilderContainerResources
*
corev1
.
ResourceRequirements
`json:"imageBuilderContainerResources,omitempty"`
DockerConfigJSONSecretName
string
`json:"dockerConfigJsonSecretName,omitempty"`
DownloaderContainerEnvFrom
[]
corev1
.
EnvFromSource
`json:"downloaderContainerEnvFrom,omitempty"`
}
type
CompoundNimRequestConfigurationV1Alpha1
struct
{
Data
CompoundNimRequestData
`json:"data,omitempty"`
Version
string
`json:"version"`
}
deploy/compoundai/api-server/api/crds/consts.go
0 → 100644
View file @
5ddc7f7d
/*
* SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
crds
var
ApiVersion
string
=
"nvidia.com/v1alpha1"
type
CustomResourceType
string
const
(
CompoundNimRequest
CustomResourceType
=
"CompoundAINimRequest"
CompoundNimDeployment
CustomResourceType
=
"CompoundAINimDeployment"
)
deploy/compoundai/api-server/api/database/database.go
0 → 100644
View file @
5ddc7f7d
/*
* SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
database
import
(
"context"
"fmt"
"sync"
"github.com/rs/zerolog/log"
"github.com/dynemo-ai/dynemo/deploy/compoundai/api-server/api/common/utils"
"github.com/dynemo-ai/dynemo/deploy/compoundai/api-server/api/models"
"gorm.io/driver/postgres"
"gorm.io/gorm"
"gorm.io/gorm/schema"
)
var
db
*
gorm
.
DB
type
databaseUtil
struct
{}
var
DatabaseUtil
=
databaseUtil
{}
type
DbCtxKeyType
string
const
DbSessionKey
DbCtxKeyType
=
"session"
var
openDbOnce
=
sync
.
Once
{}
const
(
DB_USER
=
"DB_USER"
DB_PASSWORD
=
"DB_PASSWORD"
DB_HOST
=
"DB_HOST"
DB_NAME
=
"DB_NAME"
DB_PORT
=
"DB_PORT"
)
func
SetupDB
()
{
openDbOnce
.
Do
(
func
()
{
var
err
error
db
,
err
=
openDBConnection
()
if
err
!=
nil
{
log
.
Fatal
()
.
Msgf
(
"Could not connect to Postgres database! %s"
,
err
.
Error
())
}
db
.
AutoMigrate
(
&
models
.
Cluster
{})
db
.
AutoMigrate
(
&
models
.
Deployment
{})
db
.
AutoMigrate
(
&
models
.
DeploymentRevision
{})
db
.
AutoMigrate
(
&
models
.
DeploymentTarget
{})
db
.
AutoMigrate
(
&
models
.
CompoundComponent
{})
db
.
Exec
(
"CREATE UNIQUE INDEX uk_cluster_orgId_name ON cluster (organization_id, name);"
)
db
.
Exec
(
"CREATE UNIQUE INDEX uk_deployment_clusterId_name ON deployment (cluster_id, name);"
)
})
}
func
openDBConnection
()
(
*
gorm
.
DB
,
error
)
{
dbUser
,
err
:=
utils
.
MustGetEnv
(
DB_USER
)
if
err
!=
nil
{
log
.
Error
()
.
Msgf
(
"Failed to get %s from env: %s"
,
DB_USER
,
err
.
Error
())
return
nil
,
err
}
dbPass
,
err
:=
utils
.
MustGetEnv
(
DB_PASSWORD
)
if
err
!=
nil
{
log
.
Error
()
.
Msgf
(
"Failed to get %s from env: %s"
,
DB_PASSWORD
,
err
.
Error
())
return
nil
,
err
}
dbHost
,
err
:=
utils
.
MustGetEnv
(
DB_HOST
)
if
err
!=
nil
{
log
.
Error
()
.
Msgf
(
"Failed to get %s from env: %s"
,
DB_HOST
,
err
.
Error
())
return
nil
,
err
}
dbPort
,
err
:=
utils
.
MustGetEnv
(
DB_PORT
)
if
err
!=
nil
{
log
.
Error
()
.
Msgf
(
"Failed to get %s from env: %s"
,
DB_PORT
,
err
.
Error
())
return
nil
,
err
}
dbName
,
err
:=
utils
.
MustGetEnv
(
DB_NAME
)
if
err
!=
nil
{
log
.
Error
()
.
Msgf
(
"Failed to get %s from env: %s"
,
DB_NAME
,
err
.
Error
())
return
nil
,
err
}
uri
:=
fmt
.
Sprintf
(
"postgres://%s:%s@%s:%s/%s"
,
dbUser
,
dbPass
,
dbHost
,
dbPort
,
dbName
,
)
log
.
Info
()
.
Msgf
(
"Connecting to Postgres"
)
db
,
err
:=
gorm
.
Open
(
postgres
.
Open
(
uri
),
&
gorm
.
Config
{
NamingStrategy
:
schema
.
NamingStrategy
{
SingularTable
:
true
},
PrepareStmt
:
false
,
})
if
err
!=
nil
{
return
nil
,
err
}
log
.
Info
()
.
Msgf
(
"Successfully connected to Postgres"
)
return
db
,
nil
}
func
(
d
*
databaseUtil
)
GetDB
(
ctx
context
.
Context
)
*
gorm
.
DB
{
return
db
.
WithContext
(
ctx
)
}
func
(
d
*
databaseUtil
)
GetDBSession
(
ctx
context
.
Context
)
*
gorm
.
DB
{
session
:=
ctx
.
Value
(
DbSessionKey
)
if
session
!=
nil
{
db
:=
session
.
(
*
gorm
.
DB
)
return
db
}
return
d
.
GetDB
(
ctx
)
}
func
(
d
*
databaseUtil
)
StartTransaction
(
ctx
context
.
Context
)
(
*
gorm
.
DB
,
context
.
Context
,
func
(
error
),
error
)
{
session
:=
ctx
.
Value
(
DbSessionKey
)
if
session
!=
nil
{
db_
:=
session
.
(
*
gorm
.
DB
)
return
db_
,
ctx
,
func
(
err
error
)
{},
nil
}
db
:=
d
.
GetDB
(
ctx
)
tx
:=
db
.
Begin
()
if
tx
.
Error
!=
nil
{
return
nil
,
ctx
,
func
(
err
error
)
{},
tx
.
Error
}
ctx
=
context
.
WithValue
(
ctx
,
DbSessionKey
,
tx
)
return
tx
,
ctx
,
func
(
err
error
)
{
select
{
case
<-
ctx
.
Done
()
:
return
default
:
}
// nolint: gocritic
if
p
:=
recover
();
p
!=
nil
{
tx
.
Rollback
()
panic
(
p
)
}
else
if
err
!=
nil
{
tx
.
Rollback
()
}
else
{
tx
.
Commit
()
}
},
nil
}
deploy/compoundai/api-server/api/main.go
0 → 100644
View file @
5ddc7f7d
/*
* SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
main
import
"github.com/dynemo-ai/dynemo/deploy/compoundai/api-server/api/runtime"
const
(
port
=
8181
)
func
main
()
{
runtime
.
Runtime
.
StartServer
(
port
)
}
deploy/compoundai/api-server/api/mocks/mock.go
0 → 100644
View file @
5ddc7f7d
/*
* SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
mocks
import
(
"time"
"github.com/dynemo-ai/dynemo/deploy/compoundai/api-server/api/schemas"
)
var
mockedUid
=
"nvid1a11-1234-5678-9abc-def012345678"
func
DefaultUser
()
*
schemas
.
UserSchema
{
return
&
schemas
.
UserSchema
{
ResourceSchema
:
schemas
.
ResourceSchema
{
BaseSchema
:
schemas
.
BaseSchema
{
Uid
:
mockedUid
,
CreatedAt
:
time
.
Now
(),
UpdatedAt
:
time
.
Now
(),
DeletedAt
:
nil
,
},
Name
:
"nvidia-user"
,
},
FirstName
:
"Compound"
,
LastName
:
"AI"
,
Email
:
"compoundai@nvidia.com"
,
}
}
func
DefaultOrg
()
*
schemas
.
OrganizationSchema
{
return
&
schemas
.
OrganizationSchema
{
ResourceSchema
:
schemas
.
ResourceSchema
{
BaseSchema
:
schemas
.
BaseSchema
{
Uid
:
mockedUid
,
CreatedAt
:
time
.
Now
(),
UpdatedAt
:
time
.
Now
(),
DeletedAt
:
nil
,
},
Name
:
"nvidia-org"
,
ResourceType
:
schemas
.
ResourceTypeOrganization
,
Labels
:
[]
schemas
.
LabelItemSchema
{},
},
Description
:
"nvidia-org-desc"
,
}
}
func
DefaultOrgMember
()
*
schemas
.
OrganizationMemberSchema
{
return
&
schemas
.
OrganizationMemberSchema
{
BaseSchema
:
schemas
.
BaseSchema
{
Uid
:
mockedUid
,
CreatedAt
:
time
.
Now
(),
UpdatedAt
:
time
.
Now
(),
DeletedAt
:
nil
,
},
Role
:
schemas
.
MemberRoleAdmin
,
Creator
:
DefaultUser
(),
User
:
*
DefaultUser
(),
Organization
:
*
DefaultOrg
(),
}
}
deploy/compoundai/api-server/api/models/associate.go
0 → 100644
View file @
5ddc7f7d
/*
* SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
models
type
ClusterAssociate
struct
{
ClusterId
uint
`json:"cluster_id"`
AssociatedClusterCache
*
Cluster
`gorm:"foreignkey:ClusterId"`
}
type
DeploymentAssociate
struct
{
DeploymentId
uint
`json:"deployment_id"`
AssociatedDeploymentCache
*
Deployment
`gorm:"foreignkey:DeploymentId;constraint:OnDelete:CASCADE;"`
}
type
DeploymentRevisionAssociate
struct
{
DeploymentRevisionId
uint
`json:"deployment_revision_id"`
AssociatedDeploymentRevisionCache
*
DeploymentRevision
`gorm:"foreignkey:DeploymentRevisionId;constraint:OnDelete:CASCADE;"`
}
type
CompoundNimVersionAssociate
struct
{
CompoundNimVersionId
string
`json:"compound_nim_version_id"`
CompoundNimVersionTag
string
`json:"compound_nim_version_tag"`
}
type
DmsAssociate
struct
{
KubeRequestId
string
KubeDeploymentId
string
}
type
OrganizationAssociate
struct
{
OrganizationId
string
`json:"organization_id"`
// Set via http headers
}
type
CreatorAssociate
struct
{
UserId
string
`json:"user_id"`
// Set via http headers
}
Prev
1
2
3
4
5
6
…
12
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment