55
66 "github.com/jumppad-labs/hclconfig/types"
77 "github.com/jumppad-labs/jumppad/pkg/config"
8- ctypes "github.com/jumppad-labs/jumppad/pkg/config/resources/container"
8+ "github.com/jumppad-labs/jumppad/pkg/config/resources/container"
99 "github.com/jumppad-labs/jumppad/pkg/utils"
1010)
1111
@@ -18,17 +18,29 @@ type Cluster struct {
1818 // embedded type holding name, etc.
1919 types.ResourceBase `hcl:",remain"`
2020
21- Networks []ctypes .NetworkAttachment `hcl:"network,block" json:"networks,omitempty"` // Attach to the correct network // only when Image is specified
21+ Networks []container .NetworkAttachment `hcl:"network,block" json:"networks,omitempty"` // Attach to the correct network // only when Image is specified
2222
23- Image * ctypes .Image `hcl:"image,block" json:"images,omitempty"` // optional image to use when creating the cluster
24- Nodes int `hcl:"nodes,optional" json:"nodes,omitempty"`
25- Volumes []ctypes .Volume `hcl:"volume,block" json:"volumes,omitempty"` // volumes to attach to the cluster
23+ Image * container .Image `hcl:"image,block" json:"images,omitempty"` // optional image to use when creating the cluster
24+ Nodes int `hcl:"nodes,optional" json:"nodes,omitempty"`
25+ Volumes []container .Volume `hcl:"volume,block" json:"volumes,omitempty"` // volumes to attach to the cluster
2626
2727 // Images that will be copied from the local docker cache to the cluster
28- CopyImages []ctypes .Image `hcl:"copy_image,block" json:"copy_images,omitempty"`
28+ CopyImages []container .Image `hcl:"copy_image,block" json:"copy_images,omitempty"`
2929
30- Ports []ctypes.Port `hcl:"port,block" json:"ports,omitempty"` // ports to expose
31- PortRanges []ctypes.PortRange `hcl:"port_range,block" json:"port_ranges,omitempty"` // range of ports to expose
30+ Ports []container.Port `hcl:"port,block" json:"ports,omitempty"` // ports to expose
31+ PortRanges []container.PortRange `hcl:"port_range,block" json:"port_ranges,omitempty"` // range of ports to expose
32+
33+ /*
34+ Define resource constraints for the cluster
35+
36+ ```hcl
37+ resources {
38+ cpu = 100
39+ memory = 1024
40+ }
41+ ```
42+ */
43+ Resources * container.Resources `hcl:"resources,block" json:"resources,omitempty"`
3244
3345 Environment map [string ]string `hcl:"environment,optional" json:"environment,omitempty"` // environment variables to set when starting the container
3446
@@ -83,13 +95,20 @@ func (k *Cluster) Process() error {
8395 }
8496
8597 if k .Image == nil {
86- k .Image = & ctypes .Image {Name : fmt .Sprintf ("%s:%s" , k3sBaseImage , k3sBaseVersion )}
98+ k .Image = & container .Image {Name : fmt .Sprintf ("%s:%s" , k3sBaseImage , k3sBaseVersion )}
8799 }
88100
89101 for i , v := range k .Volumes {
90102 k .Volumes [i ].Source = utils .EnsureAbsolute (v .Source , k .Meta .File )
91103 }
92104
105+ if k .Resources == nil {
106+ k .Resources = & container.Resources {
107+ CPU : 500 ,
108+ Memory : 2024 ,
109+ }
110+ }
111+
93112 // do we have an existing resource in the state?
94113 // if so we need to set any computed resources for dependents
95114 c , err := config .LoadState ()
@@ -104,6 +123,7 @@ func (k *Cluster) Process() error {
104123 k .ConnectorPort = kstate .ConnectorPort
105124 k .ExternalIP = kstate .ExternalIP
106125 k .KubeConfig = kstate .KubeConfig
126+ k .Resources = kstate .Resources
107127
108128 // add the network addresses
109129 for _ , a := range kstate .Networks {
0 commit comments