Skip to content

Commit

Permalink
set property to omiempty
Browse files Browse the repository at this point in the history
  • Loading branch information
simonycj committed Jul 17, 2024
1 parent 0a5b26e commit c075fed
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 44 deletions.
86 changes: 43 additions & 43 deletions cmd/open-hydra-server/app/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,46 +59,46 @@ type (
OpenHydraServerConfig struct {
// in case of we want to control total pod number in cluster
// -1 not limit pod allocatable will be count by resource wise
PodAllocatableLimit int64 `json:"pod_allocatable_limit" yaml:"podAllocatableLimit"`
PodAllocatableLimit int64 `json:"pod_allocatable_limit,omitempty" yaml:"podAllocatableLimit,omitempty"`
// default = 2000
// note unit is m
DefaultCpuPerDevice uint64 `json:"default_cpu_per_device" yaml:"defaultCpuPerDevice"`
DefaultCpuPerDevice uint64 `json:"default_cpu_per_device,omitempty" yaml:"defaultCpuPerDevice,omitempty"`
// default = 8192
// note unit is Mi
DefaultRamPerDevice uint64 `json:"default_ram_per_device" yaml:"defaultRamPerDevice"`
DefaultRamPerDevice uint64 `json:"default_ram_per_device,omitempty" yaml:"defaultRamPerDevice,omitempty"`
// default = 0
DefaultGpuPerDevice uint8 `json:"default_gpu_per_device" yaml:"defaultGpuPerDevice"`
DefaultGpuPerDevice uint8 `json:"default_gpu_per_device,omitempty" yaml:"defaultGpuPerDevice,omitempty"`
// default = "/open-hydra/public-dataset"
// all dataset upload by user will be store in this path
PublicDatasetBasePath string `json:"dataset_base_path" yaml:"datasetBasePath"`
PublicCourseBasePath string `json:"course_base_path" yaml:"courseBasePath"`
PublicDatasetMaxSize int64 `json:"dataset_max_size" yaml:"datasetMaxSize"`
PublicCourseMaxSize int64 `json:"course_max_size" yaml:"courseMaxSize"`
PublicDatasetBasePath string `json:"dataset_base_path,omitempty" yaml:"datasetBasePath,omitempty"`
PublicCourseBasePath string `json:"course_base_path,omitempty" yaml:"courseBasePath,omitempty"`
PublicDatasetMaxSize int64 `json:"dataset_max_size,omitempty" yaml:"datasetMaxSize,omitempty"`
PublicCourseMaxSize int64 `json:"course_max_size,omitempty" yaml:"courseMaxSize,omitempty"`
// default = "hostpath", hostpath or nfs
// hostpath: open-hydra-server will use hostpath to mount dataset most likely for aio server or test
// nfs: open-hydra-server will use nfs to mount dataset most likely for production
PublicDatasetVolumeType string `json:"dataset_volume_type" yaml:"datasetVolumeType"`
PublicDatasetVolumeType string `json:"dataset_volume_type,omitempty" yaml:"datasetVolumeType,omitempty"`
// default = "/root/public-dataset"
PublicDatasetStudentMountPath string `json:"dataset_student_mount_path" yaml:"datasetStudentMountPath"`
PublicCourseStudentMountPath string `json:"course_student_mount_path" yaml:"courseStudentMountPath"`
PublicDatasetStudentMountPath string `json:"dataset_student_mount_path,omitempty" yaml:"datasetStudentMountPath,omitempty"`
PublicCourseStudentMountPath string `json:"course_student_mount_path,omitempty" yaml:"courseStudentMountPath,omitempty"`
// should be no default value but fill it in installation script, because it is a runtime value
// if not set we won't be able to start gpu pod at all
DefaultGpuDriver string `json:"default_gpu_driver" yaml:"defaultGpuDriver"`
DefaultGpuDriver string `json:"default_gpu_driver,omitempty" yaml:"defaultGpuDriver,omitempty"`
// gpu resource keys that predefine for open-hydra-server to discover gpu resource
GpuResourceKeys []string `json:"gpu_resource_keys" yaml:"gpuResourceKeys"`
GpuResourceKeys []string `json:"gpu_resource_keys,omitempty" yaml:"gpuResourceKeys,omitempty"`
ServerIP string `json:"server_ip" yaml:"serverIP"`
KubeConfig *rest.Config
LeaderElection *LeaderElection `json:"leader_election" yaml:"leaderElection,omitempty"`
MySqlConfig *MySqlConfig `json:"mysql_config" yaml:"mysqlConfig,omitempty"`
EtcdConfig *EtcdConfig `json:"etcd_config" yaml:"etcdConfig,omitempty"`
DBType string `json:"db_type" yaml:"dbType"`
LeaderElection *LeaderElection `json:"leader_election,omitempty" yaml:"leaderElection,omitempty"`
MySqlConfig *MySqlConfig `json:"mysql_config,omitempty" yaml:"mysqlConfig,omitempty"`
EtcdConfig *EtcdConfig `json:"etcd_config,omitempty" yaml:"etcdConfig,omitempty"`
DBType string `json:"db_type,omitempty" yaml:"dbType,omitempty"`
DisableAuth bool `json:"disable_auth" yaml:"disableAuth"`
PatchResourceNotRelease bool `json:"patch_resource_not_release" yaml:"patchResourceNotRelease"`
CpuOverCommitRate uint8 `json:"cpu_over_commit_rate" yaml:"cpuOverCommitRate"`
MemoryOverCommitRate uint8 `json:"memory_over_commit_rate" yaml:"memoryOverCommitRate"`
AuthDelegateConfig *AuthDelegateConfig `json:"auth_delegate_config" yaml:"authDelegateConfig,omitempty"`
MaximumPortsPerSandbox uint8 `json:"maximum_ports_per_sandbox" yaml:"maximumPortsPerSandbox"`
WorkspacePath string `json:"workspace_path" yaml:"workspacePath"`
PatchResourceNotRelease bool `json:"patch_resource_not_release,omitempty" yaml:"patchResourceNotRelease,omitempty"`
CpuOverCommitRate uint8 `json:"cpu_over_commit_rate,omitempty" yaml:"cpuOverCommitRate,omitempty"`
MemoryOverCommitRate uint8 `json:"memory_over_commit_rate,omitempty" yaml:"memoryOverCommitRate,omitempty"`
AuthDelegateConfig *AuthDelegateConfig `json:"auth_delegate_config,omitempty" yaml:"authDelegateConfig,omitempty"`
MaximumPortsPerSandbox uint8 `json:"maximum_ports_per_sandbox,omitempty" yaml:"maximumPortsPerSandbox,omitempty"`
WorkspacePath string `json:"workspace_path,omitempty" yaml:"workspacePath,omitempty"`
}
)

Expand Down Expand Up @@ -140,36 +140,36 @@ func DefaultConfig() *OpenHydraServerConfig {
}

type EtcdConfig struct {
Endpoints []string `json:"endpoints" yaml:"endpoints"`
CAFile string `json:"ca_file" yaml:"caFile"`
CertFile string `json:"cert_file" yaml:"certFile"`
KeyFile string `json:"key_file" yaml:"keyFile"`
Endpoints []string `json:"endpoints,omitempty" yaml:"endpoints,omitempty"`
CAFile string `json:"ca_file,omitempty" yaml:"caFile,omitempty"`
CertFile string `json:"cert_file,omitempty" yaml:"certFile,omitempty"`
KeyFile string `json:"key_file,omitempty" yaml:"keyFile,omitempty"`
}

type MySqlConfig struct {
Address string `json:"address" yaml:"address"`
Port uint16 `json:"port" yaml:"port"`
Username string `json:"username" yaml:"username"`
Password string `json:"password" yaml:"password"`
DataBaseName string `json:"database_name" yaml:"databaseName"`
Protocol string `json:"protocol" yaml:"protocol"`
Character string `json:"character" yaml:"character"`
Collation string `json:"collation" yaml:"collation"`
Address string `json:"address,omitempty" yaml:"address,omitempty"`
Port uint16 `json:"port,omitempty" yaml:"port,omitempty"`
Username string `json:"username,omitempty" yaml:"username,omitempty"`
Password string `json:"password,omitempty" yaml:"password,omitempty"`
DataBaseName string `json:"database_name,omitempty" yaml:"databaseName,omitempty"`
Protocol string `json:"protocol,omitempty" yaml:"protocol,omitempty"`
Character string `json:"character,omitempty" yaml:"character,omitempty"`
Collation string `json:"collation,omitempty" yaml:"collation,omitempty"`
}

type AuthDelegateConfig struct {
// if KeystoneConfig is set to nil then auth plugin will fall backup to database auth
KeystoneConfig *KeystoneConfig `json:"keystone_config" yaml:"keystoneConfig"`
KeystoneConfig *KeystoneConfig `json:"keystone_config,omitempty" yaml:"keystoneConfig,omitempty"`
}

type KeystoneConfig struct {
Endpoint string `json:"endpoint" yaml:"endpoint"`
Username string `json:"username" yaml:"username"`
Password string `json:"password" yaml:"password"`
DomainId string `json:"domain_id" yaml:"domainId"`
ProjectId string `json:"project_id" yaml:"projectId"`
TokenKeyInResponse string `json:"token_key_in_response" yaml:"tokenKeyInResponse"`
TokenKeyInRequest string `json:"token_key_in_request" yaml:"tokenKeyInRequest"`
Endpoint string `json:"endpoint,omitempty" yaml:"endpoint,omitempty"`
Username string `json:"username,omitempty" yaml:"username,omitempty"`
Password string `json:"password,omitempty" yaml:"password,omitempty"`
DomainId string `json:"domain_id,omitempty" yaml:"domainId,omitempty"`
ProjectId string `json:"project_id,omitempty" yaml:"projectId,omitempty"`
TokenKeyInResponse string `json:"token_key_in_response,omitempty" yaml:"tokenKeyInResponse,omitempty"`
TokenKeyInRequest string `json:"token_key_in_request,omitempty" yaml:"tokenKeyInRequest,omitempty"`
}

func DefaultEtcdConfig() *EtcdConfig {
Expand Down
1 change: 1 addition & 0 deletions deploy/install-open-hydra.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ data:
defaultRamPerDevice: 8192
defaultGpuPerDevice: 0
datasetBasePath: /mnt/public-dataset
courseBasePath: /mnt/public-course
workspacePath: /mnt/workspace
defaultGpuDriver: nvidia.com/gpu
gpuResourceKeys:
Expand Down
13 changes: 12 additions & 1 deletion pkg/open-hydra/k8s/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package k8s

import (
"context"
"encoding/json"
"fmt"
"log/slog"
"open-hydra/pkg/open-hydra/apis"
Expand Down Expand Up @@ -180,7 +181,17 @@ func (help *DefaultHelper) CreateDeployment(deployParameter *DeploymentParameter

deployment.Spec.Template.Spec.Affinity = deployParameter.Affinity

_, err := deployParameter.Client.AppsV1().Deployments(deployParameter.Namespace).Create(context.TODO(), deployment, metaV1.CreateOptions{})
debugDeploy, err := json.Marshal(deployment)
if err != nil {
slog.Error("failed to marshal deployment", "error", err)
return err
}

fmt.Println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`")
slog.Info("deployment", "deployment", string(debugDeploy))
fmt.Println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`")

_, err = deployParameter.Client.AppsV1().Deployments(deployParameter.Namespace).Create(context.TODO(), deployment, metaV1.CreateOptions{})
if err != nil {
return err
}
Expand Down

0 comments on commit c075fed

Please sign in to comment.