Skip to content

Commit

Permalink
update fargate (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
saamalik authored May 27, 2021
1 parent f6f700d commit ba936f6
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 40 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/prometheus/common v0.23.0
github.com/robfig/cron v1.2.0
github.com/spectrocloud/gomi v1.9.1-0.20210519044035-5333c9359877
github.com/spectrocloud/hapi v1.9.1-0.20210524095142-4a39f2af8c8f
github.com/spectrocloud/hapi v1.9.1-0.20210527064737-d446d50937fb
)

// replace github.com/spectrocloud/hapi => ../hapi
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -855,8 +855,8 @@ github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasO
github.com/spectrocloud/gomi v0.0.0-20201113051324-08a1179400db/go.mod h1:rPAwipFWzjYkTfx44KmQazP1NR2cnHe7HSFZkc63mf4=
github.com/spectrocloud/gomi v1.9.1-0.20210519044035-5333c9359877 h1:rbfwoaCqN862q0LVra0UistoS+QRhM3D/e+pNnwy7zw=
github.com/spectrocloud/gomi v1.9.1-0.20210519044035-5333c9359877/go.mod h1:rPAwipFWzjYkTfx44KmQazP1NR2cnHe7HSFZkc63mf4=
github.com/spectrocloud/hapi v1.9.1-0.20210524095142-4a39f2af8c8f h1:qX/AdpC3NDW6sBR5sG/Ww9LvsgM9xzKN4xFN4G7/U9A=
github.com/spectrocloud/hapi v1.9.1-0.20210524095142-4a39f2af8c8f/go.mod h1:PY/aOnWz7w1hZE9RIEKeSYhuHJDpaeKHfsQ97pQ/yZk=
github.com/spectrocloud/hapi v1.9.1-0.20210527064737-d446d50937fb h1:giaidR71d+FV//Yznm+ZGKJyJ1Rtg11IMItAEFp/kMc=
github.com/spectrocloud/hapi v1.9.1-0.20210527064737-d446d50937fb/go.mod h1:PY/aOnWz7w1hZE9RIEKeSYhuHJDpaeKHfsQ97pQ/yZk=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
github.com/spf13/cast v1.2.0/go.mod h1:r2rcYCSwa1IExKTDiTfzaxqT2FNHs8hODu4LnUfgKEg=
Expand Down
12 changes: 12 additions & 0 deletions pkg/client/cluster_eks.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ func (h *V1alpha1Client) DeleteMachinePoolEks(cloudConfigId string, machinePoolN
return err
}

func (h *V1alpha1Client) UpdateFargateProfiles(cloudConfigId string, fargateProfiles *models.V1alpha1EksFargateProfiles) error {
client, err := h.getClusterClient()
if err != nil {
return nil
}
params := clusterC.NewV1alpha1CloudConfigsEksUIDFargateProfilesUpdateParamsWithContext(h.ctx).
WithConfigUID(cloudConfigId).
WithBody(fargateProfiles)
_, err = client.V1alpha1CloudConfigsEksUIDFargateProfilesUpdate(params)
return err
}

func (h *V1alpha1Client) GetCloudConfigEks(configUID string) (*models.V1alpha1EksCloudConfig, error) {
client, err := h.getClusterClient()
if err != nil {
Expand Down
25 changes: 0 additions & 25 deletions spectrocloud/cluster_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,31 +210,6 @@ func resourceMachinePoolEksHash(v interface{}) int {
return int(hash(buf.String()))
}

func resourceFargateProfileEksHash(v interface{}) int {
var buf bytes.Buffer
m := v.(map[string]interface{})
buf.WriteString(fmt.Sprintf("%s-", m["name"].(string)))

for _, j := range m["subnets"].([]interface{}) {
buf.WriteString(fmt.Sprintf("%s-", j.(string)))
}

for i, j := range m["additional_tags"].(map[string]interface{}) {
buf.WriteString(fmt.Sprintf("%s-%s", i, j.(string)))
}

for i, j := range m["selector"].([]interface{}) {
ins := j.(map[string]interface{})
buf.WriteString(fmt.Sprintf("%d-%s-", i, ins["namespace"].(string)))

for i2, j2 := range m["labels"].(map[string]interface{}) {
buf.WriteString(fmt.Sprintf("%s-%s", i2, j2.(string)))
}
}

return int(hash(buf.String()))
}

func resourceMachinePoolVsphereHash(v interface{}) int {
var buf bytes.Buffer
m := v.(map[string]interface{})
Expand Down
29 changes: 17 additions & 12 deletions spectrocloud/resource_cluster_eks.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,47 +204,39 @@ func resourceClusterEks() *schema.Resource {
"fargate_profile": {
Type: schema.TypeList,
Required: true,
ForceNew: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
//ForceNew: true,
},

"subnets": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},

"additional_tags": {
Type: schema.TypeMap,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},

"selector": {
Type: schema.TypeList,
Required: true,
ForceNew: true,
//MinItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"namespace": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"labels": {
Type: schema.TypeMap,
Optional: true,
ForceNew: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Expand Down Expand Up @@ -413,10 +405,23 @@ func resourceClusterEksUpdate(ctx context.Context, d *schema.ResourceData, m int
cloudConfigId := d.Get("cloud_config_id").(string)


//if d.HasChange("fargate_profile") {
// cluster := toEksCluster(d)
// uid, err := c.UpdateClusterEks(cluster)
//}
if d.HasChange("fargate_profile") {
fargateProfiles := make([]*models.V1alpha1FargateProfile, 0)
for _, fargateProfile := range d.Get("fargate_profile").([]interface{}) {
f := toFargateProfileEks(fargateProfile)
fargateProfiles = append(fargateProfiles, f)
}

log.Printf("Updating fargate profiles")
fargateProfilesList := &models.V1alpha1EksFargateProfiles{
FargateProfiles: fargateProfiles,
}

err := c.UpdateFargateProfiles(cloudConfigId, fargateProfilesList)
if err != nil {
return diag.FromErr(err)
}
}

_ = d.Get("machine_pool")

Expand Down

0 comments on commit ba936f6

Please sign in to comment.