Skip to content

Commit

Permalink
Merge pull request #637 from kthcloud/dev
Browse files Browse the repository at this point in the history
Maintenance Update
  • Loading branch information
saffronjam committed Jun 2, 2024
2 parents ee2eed2 + 6a8b37e commit a3fe776
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
7 changes: 1 addition & 6 deletions export/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@
* Types for kthcloud go-deploy API
* */

// v1 (CloudStack)
import * as v1Body from "./types/v1/body";
import * as v1Query from "./types/v1/query";
import * as v1Uri from "./types/v1/uri";

// v2 (Kubevirt)
import * as v2Body from "./types/v2/body";
import * as v2Query from "./types/v2/query";
import * as v2Uri from "./types/v2/uri";

export { v1Body, v1Query, v1Uri, v2Body, v2Query, v2Uri };
export { v2Body, v2Query, v2Uri };
2 changes: 1 addition & 1 deletion service/v2/deployments/resources/harbor_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (hg *HarborGenerator) Repository() *models.RepositoryPublic {
// Webhook returns a models.WebhookPublic that should be created
func (hg *HarborGenerator) Webhook() *models.WebhookPublic {
if hg.deployment != nil {
webhookTarget := fmt.Sprintf("%s/v1/hooks/deployments/harbor", config.Config.ExternalUrl)
webhookTarget := fmt.Sprintf("%s/v2/hooks/deployments/harbor", config.Config.ExternalUrl)

we := models.WebhookPublic{
// "Name" does not matter and will be imported from Harbor if "Target" matches with existing webhook
Expand Down
19 changes: 17 additions & 2 deletions service/v2/deployments/resources/k8s_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ func (kg *K8sGenerator) Deployments() []models.DeploymentPublic {
})

limits := models.Limits{
CPU: fmt.Sprintf("%.1f", mainApp.CpuCores),
CPU: formatCpuString(mainApp.CpuCores),
Memory: fmt.Sprintf("%dMi", int(mainApp.RAM*1000)),
}

requests := models.Requests{
CPU: fmt.Sprintf("%.1f", math.Min(config.Config.Deployment.Resources.Requests.CPU, mainApp.CpuCores)),
CPU: formatCpuString(math.Min(config.Config.Deployment.Resources.Requests.CPU, mainApp.CpuCores)),
Memory: fmt.Sprintf("%dMi", int(math.Min(config.Config.Deployment.Resources.Requests.RAM, mainApp.RAM)*1000)),
}

Expand Down Expand Up @@ -552,3 +552,18 @@ func getExternalFQDN(name string, zone *configModels.Zone) string {

return fmt.Sprintf("%s.%s", name, fqdn)
}

// formatCpuString formats the CPU string.
// It ensures the same is returned by K8s after creation.
func formatCpuString(cpus float64) string {
// Round to one decimal, e.g. 0.12 -> 0.1, 0.16 -> 0.2
oneDec := math.Round(cpus*10) / 10

// If whole number, return as int, e.g. 1.0 -> 1
if oneDec == float64(int(oneDec)) {
return fmt.Sprintf("%d", int(oneDec))
}

// Otherwise, return as milli CPU, e.g. 0.1 -> 100m
return fmt.Sprintf("%dm", int(oneDec*1000))
}

0 comments on commit a3fe776

Please sign in to comment.