k8s, k8s_wg: single worker add/delete support; github actions support

2.0
kjubybot 3 years ago
parent ef7fa62e79
commit a3da44f2ad

@ -0,0 +1,37 @@
name: Release to registry
on:
push:
tags:
- 'v*'
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Fetch all tags
run: git fetch --force --tags
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: 1.17
- name: Import GPG key
id: import_gpg
uses: crazy-max/ghaction-import-gpg@v4
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.PASSPHRASE }}
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
args: release --rm-dist --release-notes CHANGELOG.md
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}

@ -1,14 +1,8 @@
# Visit https://goreleaser.com for documentation on how to customize this
# behavior.
before:
hooks:
# this is just an example and not a requirement for provider building/publishing
- go mod tidy
builds:
- env:
# goreleaser does not work with CGO, it could also complicate
# usage by users in CI/CD systems like Terraform Cloud where
# they are unable to install libraries.
- CGO_ENABLED=0
mod_timestamp: '{{ .CommitTimestamp }}'
flags:
@ -37,11 +31,9 @@ checksum:
signs:
- artifacts: checksum
args:
# if you are using this in a GitHub action or some other automated pipeline, you
# need to pass the batch flag to indicate its not interactive.
- "--batch"
- "--local-user"
- "{{ .Env.GPG_FINGERPRINT }}" # set this environment variable for your signing key
- "{{ .Env.GPG_FINGERPRINT }}"
- "--output"
- "${signature}"
- "--detach-sign"
@ -50,7 +42,5 @@ release:
extra_files:
- glob: 'terraform-registry-manifest.json'
name_template: '{{ .ProjectName }}_{{ .Version }}_manifest.json'
# If you want to manually examine the release before its live, uncomment this line:
# draft: true
changelog:
skip: true
skip: false

@ -0,0 +1,16 @@
## 2.0
### New data sources
- image
- image\_list
- grid
- grid\_list
- image\_list\_stacks
### New resources
- image
- virtual\_image
- cdrom\_image
- delete\_images
- k8s
- k8s\_wg

@ -583,12 +583,16 @@ const VinsDeleteAPI = "/restmachine/cloudapi/vins/delete"
//K8sNodeRecord represents a worker/master group
type K8sNodeRecord struct {
ID int `json:"id"`
Name string `json:"name"`
Disk int `json:"disk"`
Cpu int `json:"cpu"`
Num int `json:"num"`
Ram int `json:"ram"`
ID int `json:"id"`
Name string `json:"name"`
Disk int `json:"disk"`
Cpu int `json:"cpu"`
Num int `json:"num"`
Ram int `json:"ram"`
DetailedInfo []struct {
ID int `json:"id"`
Name string `json:"name"`
} `json:"detailedInfo"`
}
//K8sRecord represents k8s instance
@ -614,6 +618,9 @@ const K8sDeleteAPI = "/restmachine/cloudapi/k8s/delete"
const K8sWgCreateAPI = "/restmachine/cloudapi/k8s/workersGroupAdd"
const K8sWgDeleteAPI = "/restmachine/cloudapi/k8s/workersGroupDelete"
const K8sWorkerAddAPI = "/restmachine/cloudapi/k8s/workerAdd"
const K8sWorkerDeleteAPI = "/restmachine/cloudapi/k8s/deleteWorkerFromGroup"
const K8sGetConfigAPI = "/restmachine/cloudapi/k8s/getConfig"
//Blasphemous workaround for parsing Result value

@ -72,7 +72,6 @@ func nodeK8sSubresourceSchemaMake() map[string]*schema.Schema {
"num": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
Description: "Number of nodes to create.",
},

@ -165,13 +165,46 @@ func resourceK8sUpdate(d *schema.ResourceData, m interface{}) error {
log.Debugf("resourceK8sUpdate: called with id %s, rg %d", d.Id(), d.Get("rg_id").(int))
controller := m.(*ControllerCfg)
urlValues := &url.Values{}
urlValues.Add("k8sId", d.Id())
urlValues.Add("name", d.Get("name").(string))
_, err := controller.decortAPICall("POST", K8sUpdateAPI, urlValues)
if err != nil {
return err
if d.HasChange("name") {
urlValues := &url.Values{}
urlValues.Add("k8sId", d.Id())
urlValues.Add("name", d.Get("name").(string))
_, err := controller.decortAPICall("POST", K8sUpdateAPI, urlValues)
if err != nil {
return err
}
}
if d.HasChange("workers") {
k8s, err := utilityK8sCheckPresence(d, m)
if err != nil {
return err
}
wg := k8s.Groups.Workers[0]
urlValues := &url.Values{}
urlValues.Add("k8sId", d.Id())
urlValues.Add("workersGroupId", strconv.Itoa(wg.ID))
newWorkers := parseNode(d.Get("workers").([]interface{}))
if newWorkers.Num > wg.Num {
urlValues.Add("num", strconv.Itoa(newWorkers.Num-wg.Num))
_, err := controller.decortAPICall("POST", K8sWorkerAddAPI, urlValues)
if err != nil {
return err
}
} else {
for i := wg.Num - 1; i >= newWorkers.Num; i-- {
urlValues.Set("workerId", strconv.Itoa(wg.DetailedInfo[i].ID))
_, err := controller.decortAPICall("POST", K8sWorkerDeleteAPI, urlValues)
if err != nil {
return err
}
}
}
}
return nil
@ -255,7 +288,6 @@ func resourceK8sSchemaMake() map[string]*schema.Schema {
"workers": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: nodeK8sSubresourceSchemaMake(),
@ -316,7 +348,7 @@ func resourceK8s() *schema.Resource {
Timeouts: &schema.ResourceTimeout{
Create: &Timeout10m,
Read: &Timeout30s,
Update: &Timeout60s,
Update: &Timeout10m,
Delete: &Timeout60s,
Default: &Timeout60s,
},

@ -101,6 +101,41 @@ func resourceK8sWgRead(d *schema.ResourceData, m interface{}) error {
return nil
}
func resourceK8sWgUpdate(d *schema.ResourceData, m interface{}) error {
log.Debugf("resourceK8sWgUpdate: called with k8s id %d", d.Get("k8s_id").(int))
controller := m.(*ControllerCfg)
wg, err := utilityK8sWgCheckPresence(d, m)
if err != nil {
return nil
}
urlValues := &url.Values{}
urlValues.Add("k8sId", strconv.Itoa(d.Get("k8s_id").(int)))
urlValues.Add("workersGroupId", d.Id())
newNum := d.Get("num").(int)
if newNum > wg.Num {
urlValues.Add("num", strconv.Itoa(newNum-wg.Num))
_, err := controller.decortAPICall("POST", K8sWorkerAddAPI, urlValues)
if err != nil {
return err
}
} else {
for i := wg.Num - 1; i >= newNum; i-- {
urlValues.Set("workerId", strconv.Itoa(wg.DetailedInfo[i].ID))
_, err := controller.decortAPICall("POST", K8sWorkerDeleteAPI, urlValues)
if err != nil {
return err
}
}
}
return nil
}
func resourceK8sWgDelete(d *schema.ResourceData, m interface{}) error {
log.Debugf("resourceK8sWgDelete: called with k8s id %d", d.Get("k8s_id").(int))
@ -158,7 +193,6 @@ func resourceK8sWgSchemaMake() map[string]*schema.Schema {
"num": {
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
Default: 1,
Description: "Number of worker nodes to create.",
},
@ -195,6 +229,7 @@ func resourceK8sWg() *schema.Resource {
Create: resourceK8sWgCreate,
Read: resourceK8sWgRead,
Update: resourceK8sWgUpdate,
Delete: resourceK8sWgDelete,
Exists: resourceK8sWgExists,
@ -205,6 +240,7 @@ func resourceK8sWg() *schema.Resource {
Timeouts: &schema.ResourceTimeout{
Create: &Timeout10m,
Read: &Timeout30s,
Update: &Timeout10m,
Delete: &Timeout60s,
Default: &Timeout60s,
},

@ -38,5 +38,6 @@ Optional:
- **default** (String)
- **delete** (String)
- **read** (String)
- **update** (String)

Loading…
Cancel
Save