Skip to content

Commit 6d20f28

Browse files
feat: support to provide container hostname (#1002) (#1012)
(cherry picked from commit a1a5d6d) Co-authored-by: Tanmoy Sarkar <57363826+tanmoysrt@users.noreply.github.com>
1 parent be28383 commit 6d20f28

13 files changed

+110
-7
lines changed

container_manager/service.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ func (m Manager) GetService(serviceName string) (Service, error) {
2626
service := Service{
2727
Name: serviceData.Spec.Name,
2828
Image: serviceData.Spec.TaskTemplate.ContainerSpec.Image,
29+
Hostname: serviceData.Spec.TaskTemplate.ContainerSpec.Hostname,
2930
Command: serviceData.Spec.TaskTemplate.ContainerSpec.Command,
3031
Env: make(map[string]string),
3132
Networks: []string{},
@@ -456,11 +457,12 @@ func (m Manager) serviceToServiceSpec(service Service) (swarm.ServiceSpec, error
456457
TaskTemplate: swarm.TaskSpec{
457458
// Set container spec
458459
ContainerSpec: &swarm.ContainerSpec{
459-
Image: service.Image,
460-
Command: service.Command,
461-
Env: env,
462-
Mounts: volumeMounts,
463-
Configs: configs,
460+
Image: service.Image,
461+
Command: service.Command,
462+
Hostname: service.Hostname,
463+
Env: env,
464+
Mounts: volumeMounts,
465+
Configs: configs,
464466
Privileges: &swarm.Privileges{
465467
NoNewPrivileges: true,
466468
AppArmor: &swarm.AppArmorOpts{

container_manager/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const (
2121
type Service struct {
2222
Name string `json:"name"`
2323
Image string `json:"image"`
24+
Hostname string `json:"hostname,omitempty"`
2425
Command []string `json:"command,omitempty"`
2526
Env map[string]string `json:"env,omitempty"`
2627
Capabilities []string `json:"capabilities,omitempty"`

swiftwave_service/core/models.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,8 @@ type Application struct {
226226
Name string `json:"name" gorm:"unique"`
227227
// ApplicationGroupID - if set, this application will be part of the application group
228228
ApplicationGroupID *string `json:"application_group_id"`
229+
// Hostname - hostname of the container, can be blank
230+
Hostname string `json:"hostname"`
229231
// Environment Variables
230232
// On change of environment variables, deployment will be triggered by force update
231233
EnvironmentVariables []EnvironmentVariable `json:"environment_variables" gorm:"foreignKey:ApplicationID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- reverse: modify "applications" table
2+
ALTER TABLE "public"."applications" DROP COLUMN "hostname";
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- modify "applications" table
2+
ALTER TABLE "public"."applications" ADD COLUMN "hostname" text NULL;

swiftwave_service/db/migrations/atlas.sum

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
h1:k1qJKQt8Sk2nl3wA2bU97eDfUN6gf5sarKNVQ0Ez5Lw=
1+
h1:dFMxl02tstPc5Nmao8FA3S7sM7mIXqsSy34VElMP2gk=
22
20240413191732_init.down.sql h1:HoitObGwuKF/akF4qg3dol2FfNTLCEuf6wHYDuCez8I=
33
20240413191732_init.up.sql h1:USKdQx/yTz1KJ0+mDwYGhKm3WzX7k+I9+6B6SxImwaE=
44
20240414051823_server_custom_ssh_port_added.down.sql h1:IC1DFQBQceTPTRdZOo5/WqytH+ZbgcKrQuMCkhArF/0=
@@ -45,3 +45,5 @@ h1:k1qJKQt8Sk2nl3wA2bU97eDfUN6gf5sarKNVQ0Ez5Lw=
4545
20240626072036_move_application_group_to_relation.up.sql h1:SNdKqmYmIZeE0JcgKiLYFajW/awiz4rXRSAKVdabPZg=
4646
20240628175617_add_extra_fields_in_app_group.down.sql h1:T/QBEilqWYysok6l2wxZAlYK1Z6ceSQLUmers5fZNig=
4747
20240628175617_add_extra_fields_in_app_group.up.sql h1:+qBOQc/2bhG1igFdUbWSsZEy01aORuPyBPvxKVXJJoA=
48+
20240906153014_add_hostname_in_application.down.sql h1:tFY94wo3G+UYA51UYt9jbfwwPTS/hCd3pG2F7smUEB8=
49+
20240906153014_add_hostname_in_application.up.sql h1:JAhs73vgSIUzt0l8M8ltRp98dVkwL5lXrdkfHvJ+arE=

swiftwave_service/graphql/application_group.resolvers.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

swiftwave_service/graphql/generated.go

Lines changed: 83 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

swiftwave_service/graphql/graphql_object_mapper.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ func applicationInputToDatabaseObject(record *model.ApplicationInput) *core.Appl
377377
LatestDeployment: *applicationInputToDeploymentDatabaseObject(record),
378378
Deployments: make([]core.Deployment, 0),
379379
IngressRules: make([]core.IngressRule, 0),
380+
Hostname: record.Hostname,
380381
Command: record.Command,
381382
Capabilities: record.Capabilities,
382383
Sysctls: record.Sysctls,
@@ -404,6 +405,7 @@ func applicationToGraphqlObject(record *core.Application) *model.Application {
404405
ResourceLimit: resourceLimitToGraphqlObject(&record.ResourceLimit),
405406
ReservedResource: reservedResourceToGraphqlObject(&record.ReservedResource),
406407
IsSleeping: record.IsSleeping,
408+
Hostname: record.Hostname,
407409
Command: record.Command,
408410
ApplicationGroupID: record.ApplicationGroupID,
409411
PreferredServerHostnames: record.PreferredServerHostnames,
@@ -753,6 +755,7 @@ func stackToApplicationsInput(applicationGroupID *string, record *stack_parser.S
753755
CodePath: nil,
754756
SourceCodeCompressedFileName: nil,
755757
ApplicationGroupID: applicationGroupID,
758+
Hostname: service.Hostname,
756759
Command: command,
757760
CustomHealthCheck: &model.ApplicationCustomHealthCheckInput{
758761
Enabled: service.CustomHealthCheck.Enabled,

swiftwave_service/graphql/model/models_gen.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)