Skip to content

Commit

Permalink
initial commit for adding machine type and count (#229)
Browse files Browse the repository at this point in the history
* initial commit for adding machine type and count

* bailing - back to cleanup

* update token values for structs and tokens

* pulls in latest main and adjusts digitalocean physicals

* cleanup and fix tokens
  • Loading branch information
jarededwards authored Nov 17, 2023
1 parent 0de9097 commit a738868
Show file tree
Hide file tree
Showing 13 changed files with 142 additions and 61 deletions.
31 changes: 28 additions & 3 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -931,12 +931,17 @@ const docTemplate = `{
"type": "string"
},
"token": {
"description": "DEPRECATED: please transition to APIToken",
"type": "string"
}
}
},
"types.Cluster": {
"type": "object",
"required": [
"node_count",
"node_type"
],
"properties": {
"_id": {
"type": "string"
Expand Down Expand Up @@ -1091,6 +1096,12 @@ const docTemplate = `{
"last_condition": {
"type": "string"
},
"node_count": {
"type": "string"
},
"node_type": {
"type": "string"
},
"state_store_create_check": {
"type": "boolean"
},
Expand Down Expand Up @@ -1147,6 +1158,8 @@ const docTemplate = `{
"domain_name",
"git_protocol",
"git_provider",
"node_count",
"node_type",
"type"
],
"properties": {
Expand Down Expand Up @@ -1227,6 +1240,12 @@ const docTemplate = `{
"google_auth": {
"$ref": "#/definitions/types.GoogleAuth"
},
"node_count": {
"type": "string"
},
"node_type": {
"type": "string"
},
"subdomain_name": {
"type": "string"
},
Expand Down Expand Up @@ -1310,9 +1329,15 @@ const docTemplate = `{
"types.Environment": {
"type": "object",
"properties": {
"_id": {
"type": "string"
},
"color": {
"type": "string"
},
"creation_timestamp": {
"type": "string"
},
"description": {
"type": "string"
},
Expand Down Expand Up @@ -1616,12 +1641,12 @@ const docTemplate = `{
"instance_size": {
"type": "string"
},
"machine_type": {
"type": "string"
},
"node_count": {
"type": "integer"
},
"node_type": {
"type": "string"
},
"status": {
"type": "string"
}
Expand Down
31 changes: 28 additions & 3 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -925,12 +925,17 @@
"type": "string"
},
"token": {
"description": "DEPRECATED: please transition to APIToken",
"type": "string"
}
}
},
"types.Cluster": {
"type": "object",
"required": [
"node_count",
"node_type"
],
"properties": {
"_id": {
"type": "string"
Expand Down Expand Up @@ -1085,6 +1090,12 @@
"last_condition": {
"type": "string"
},
"node_count": {
"type": "string"
},
"node_type": {
"type": "string"
},
"state_store_create_check": {
"type": "boolean"
},
Expand Down Expand Up @@ -1141,6 +1152,8 @@
"domain_name",
"git_protocol",
"git_provider",
"node_count",
"node_type",
"type"
],
"properties": {
Expand Down Expand Up @@ -1221,6 +1234,12 @@
"google_auth": {
"$ref": "#/definitions/types.GoogleAuth"
},
"node_count": {
"type": "string"
},
"node_type": {
"type": "string"
},
"subdomain_name": {
"type": "string"
},
Expand Down Expand Up @@ -1304,9 +1323,15 @@
"types.Environment": {
"type": "object",
"properties": {
"_id": {
"type": "string"
},
"color": {
"type": "string"
},
"creation_timestamp": {
"type": "string"
},
"description": {
"type": "string"
},
Expand Down Expand Up @@ -1610,12 +1635,12 @@
"instance_size": {
"type": "string"
},
"machine_type": {
"type": "string"
},
"node_count": {
"type": "integer"
},
"node_type": {
"type": "string"
},
"status": {
"type": "string"
}
Expand Down
22 changes: 20 additions & 2 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ definitions:
origin_ca_issuer_key:
type: string
token:
description: 'DEPRECATED: please transition to APIToken'
type: string
type: object
types.Cluster:
Expand Down Expand Up @@ -142,6 +143,10 @@ definitions:
type: string
last_condition:
type: string
node_count:
type: string
node_type:
type: string
state_store_create_check:
type: boolean
state_store_credentials:
Expand Down Expand Up @@ -172,6 +177,9 @@ definitions:
items:
$ref: '#/definitions/types.WorkloadCluster'
type: array
required:
- node_count
- node_type
type: object
types.ClusterDefinition:
properties:
Expand Down Expand Up @@ -228,6 +236,10 @@ definitions:
type: string
google_auth:
$ref: '#/definitions/types.GoogleAuth'
node_count:
type: string
node_type:
type: string
subdomain_name:
type: string
type:
Expand All @@ -245,6 +257,8 @@ definitions:
- domain_name
- git_protocol
- git_provider
- node_count
- node_type
- type
type: object
types.ClusterServiceList:
Expand Down Expand Up @@ -291,8 +305,12 @@ definitions:
type: object
types.Environment:
properties:
_id:
type: string
color:
type: string
creation_timestamp:
type: string
description:
type: string
name:
Expand Down Expand Up @@ -490,10 +508,10 @@ definitions:
$ref: '#/definitions/types.GitAuth'
instance_size:
type: string
machine_type:
type: string
node_count:
type: integer
node_type:
type: string
status:
type: string
type: object
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ require (
github.com/hashicorp/vault/api v1.9.0
github.com/joho/godotenv v1.5.1
github.com/kubefirst/metrics-client v0.2.8
github.com/kubefirst/runtime v0.3.27
github.com/kubefirst/runtime v0.3.30
github.com/minio/minio-go/v7 v7.0.49
github.com/otiai10/copy v1.7.0
github.com/rs/zerolog v1.29.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -740,8 +740,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kubefirst/metrics-client v0.2.8 h1:JfaeiBifZD/DpyYW2QVHcrhH/KWA98OmM+7c7M12qMc=
github.com/kubefirst/metrics-client v0.2.8/go.mod h1:GR7wsMcyYhd+EU67PeuMCBYFE6OJ7P/j5OI5BLOoRMc=
github.com/kubefirst/runtime v0.3.27 h1:U8u+ywqNbbSra8W4jZe+mHrkaZ0hE6JaHSWy3XQ/8GU=
github.com/kubefirst/runtime v0.3.27/go.mod h1:9egAgF5cF594mIzra5nTB1kfE57Hr/Nvl79tjLsAWCQ=
github.com/kubefirst/runtime v0.3.30 h1:faMT6w//vyt7v4qeBwh74SCNDoIv/+AWTWOnG9XyzOc=
github.com/kubefirst/runtime v0.3.30/go.mod h1:9egAgF5cF594mIzra5nTB1kfE57Hr/Nvl79tjLsAWCQ=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w=
github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
Expand Down
2 changes: 2 additions & 0 deletions internal/controller/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ func (clctrl *ClusterController) CreateTokens(kind string) interface{} {
SubdomainName: clctrl.SubdomainName,
KubefirstStateStoreBucket: clctrl.KubefirstStateStoreBucketName,
KubefirstTeam: clctrl.KubefirstTeam,
NodeType: clctrl.NodeType,
NodeCount: clctrl.NodeCount,
KubefirstVersion: env.KubefirstVersion,
Kubeconfig: clctrl.ProviderConfig.Kubeconfig, //AWS
KubeconfigPath: clctrl.ProviderConfig.Kubeconfig, //Not AWS
Expand Down
4 changes: 4 additions & 0 deletions internal/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ type ClusterController struct {
GoogleAuth pkgtypes.GoogleAuth
AwsAccessKeyID string
AwsSecretAccessKey string
NodeType string
NodeCount int

// configs
ProviderConfig providerConfigs.ProviderConfig
Expand Down Expand Up @@ -206,6 +208,8 @@ func (clctrl *ClusterController) InitController(def *pkgtypes.ClusterDefinition)

clctrl.KubefirstStateStoreBucketName = fmt.Sprintf("k1-state-store-%s-%s", clctrl.ClusterName, clusterID)
clctrl.KubefirstArtifactsBucketName = fmt.Sprintf("k1-artifacts-%s-%s", clctrl.ClusterName, clusterID)
clctrl.NodeType = def.NodeType
clctrl.NodeCount = def.NodeCount

clctrl.KubefirstTeam = env.KubefirstTeam

Expand Down
44 changes: 22 additions & 22 deletions internal/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,29 @@ import (
)

type Env struct {
ServerPort int `env:"SERVER_PORT" envDefault:"8081"`
K1AccessToken string `env:"K1_ACCESS_TOKEN"`
MongoDBHost string `env:"MONGODB_HOST,notEmpty"`
MongoDBHostType string `env:"MONGODB_HOST_TYPE,notEmpty"`
MongoDBUsername string `env:"MONGODB_USERNAME,notEmpty"`
MongoDBPassword string `env:"MONGODB_PASSWORD,notEmpty"`
KubefirstVersion string `env:"KUBEFIRST_VERSION" envDefault:"development"`
CloudProvider string `env:"CLOUD_PROVIDER"`
ClusterId string `env:"CLUSTER_ID"`
ClusterType string `env:"CLUSTER_TYPE"`
DomainName string `env:"DOMAIN_NAME"`
GitProvider string `env:"GIT_PROVIDER"`
InstallMethod string `env:"INSTALL_METHOD"`
KubefirstTeam string `env:"KUBEFIRST_TEAM" envDefault:"undefined"`
KubefirstTeamInfo string `env:"KUBEFIRST_TEAM_INFO"`
AWSRegion string `env:"AWS_REGION"`
AWSProfile string `env:"AWS_PROFILE"`
IsClusterZero bool `env:"IS_CLUSTER_ZERO"`
InCluster bool `env:"IN_CLUSTER" envDefault:"false"`
EnterpriseApiUrl string `env:"ENTERPRISE_API_URL"`
ServerPort int `env:"SERVER_PORT" envDefault:"8081"`
K1AccessToken string `env:"K1_ACCESS_TOKEN"`
MongoDBHost string `env:"MONGODB_HOST,notEmpty"`
MongoDBHostType string `env:"MONGODB_HOST_TYPE,notEmpty"`
MongoDBUsername string `env:"MONGODB_USERNAME,notEmpty"`
MongoDBPassword string `env:"MONGODB_PASSWORD,notEmpty"`
KubefirstVersion string `env:"KUBEFIRST_VERSION" envDefault:"development"`
CloudProvider string `env:"CLOUD_PROVIDER"`
ClusterId string `env:"CLUSTER_ID"`
ClusterType string `env:"CLUSTER_TYPE"`
DomainName string `env:"DOMAIN_NAME"`
GitProvider string `env:"GIT_PROVIDER"`
InstallMethod string `env:"INSTALL_METHOD"`
KubefirstTeam string `env:"KUBEFIRST_TEAM" envDefault:"undefined"`
KubefirstTeamInfo string `env:"KUBEFIRST_TEAM_INFO"`
AWSRegion string `env:"AWS_REGION"`
AWSProfile string `env:"AWS_PROFILE"`
IsClusterZero bool `env:"IS_CLUSTER_ZERO"`
InCluster bool `env:"IN_CLUSTER" envDefault:"false"`
EnterpriseApiUrl string `env:"ENTERPRISE_API_URL"`
}

func GetEnv()(Env,error) {
func GetEnv() (Env, error) {
envError := godotenv.Load(".env")

if envError != nil {
Expand All @@ -43,4 +43,4 @@ func GetEnv()(Env,error) {
}

return environment, nil
}
}
2 changes: 1 addition & 1 deletion internal/environments/defaultEnvironments.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func CreateDefaultEnvironments(mgmtCluster types.Cluster) error {
},
GitAuth: mgmtCluster.GitAuth,
InstanceSize: "", // left up to terraform
MachineType: "", //left up to terraform
NodeType: "", //left up to terraform
NodeCount: 3, //defaulted here
}

Expand Down
6 changes: 5 additions & 1 deletion pkg/providerConfigs/detokenize.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ func detokenizeGitops(path string, tokens *GitopsDirectoryValues, gitProtocol st
newContents = strings.Replace(newContents, "<KUBEFIRST_TEAM_INFO>", os.Getenv("KUBEFIRST_TEAM_INFO"), -1)
newContents = strings.Replace(newContents, "<KUBEFIRST_VERSION>", tokens.KubefirstVersion, -1)
newContents = strings.Replace(newContents, "<KUBEFIRST_STATE_STORE_BUCKET_HOSTNAME>", tokens.StateStoreBucketHostname, -1)
newContents = strings.Replace(newContents, "<WORKLOAD_CLUSTER_TERRAFORM_MODULE_URL>", "git::https://<GITOPS_REPO_NO_HTTPS_URL>//terraform/<CLOUD_PROVIDER>/modules/workload-cluster?ref=main", -1)

newContents = strings.Replace(newContents, "<NODE_TYPE>", tokens.NodeType, -1)
newContents = strings.Replace(newContents, "<NODE_COUNT>", fmt.Sprint(tokens.NodeCount), -1)

// AWS
newContents = strings.Replace(newContents, "<AWS_ACCOUNT_ID>", tokens.AwsAccountID, -1)
Expand Down Expand Up @@ -111,7 +115,7 @@ func detokenizeGitops(path string, tokens *GitopsDirectoryValues, gitProtocol st
newContents = strings.Replace(newContents, "<GIT_RUNNER>", tokens.GitRunner, -1)
newContents = strings.Replace(newContents, "<GIT_RUNNER_DESCRIPTION>", tokens.GitRunnerDescription, -1)
newContents = strings.Replace(newContents, "<GIT_RUNNER_NS>", tokens.GitRunnerNS, -1)
newContents = strings.Replace(newContents, "<GIT_URL>", tokens.GitURL, -1)
newContents = strings.Replace(newContents, "<GIT_URL>", tokens.GitURL, -1) // remove

// GitHub
newContents = strings.Replace(newContents, "<GITHUB_HOST>", tokens.GitHubHost, -1)
Expand Down
Loading

0 comments on commit a738868

Please sign in to comment.