SKE Cluster - Change field model lists to use types.List (#118)
* Change cluster model lists to types.List * Lint fix * Fix inconsistent state * Acc test fixes --------- Co-authored-by: Henrique Santos <henrique.santos@freiheit.com>
This commit is contained in:
parent
7188e13e92
commit
852516e081
3 changed files with 302 additions and 144 deletions
|
|
@ -54,20 +54,21 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Cluster struct {
|
type Cluster struct {
|
||||||
Id types.String `tfsdk:"id"` // needed by TF
|
Id types.String `tfsdk:"id"` // needed by TF
|
||||||
ProjectId types.String `tfsdk:"project_id"`
|
ProjectId types.String `tfsdk:"project_id"`
|
||||||
Name types.String `tfsdk:"name"`
|
Name types.String `tfsdk:"name"`
|
||||||
KubernetesVersion types.String `tfsdk:"kubernetes_version"`
|
KubernetesVersion types.String `tfsdk:"kubernetes_version"`
|
||||||
KubernetesVersionUsed types.String `tfsdk:"kubernetes_version_used"`
|
KubernetesVersionUsed types.String `tfsdk:"kubernetes_version_used"`
|
||||||
AllowPrivilegedContainers types.Bool `tfsdk:"allow_privileged_containers"`
|
AllowPrivilegedContainers types.Bool `tfsdk:"allow_privileged_containers"`
|
||||||
NodePools []NodePool `tfsdk:"node_pools"`
|
NodePools types.List `tfsdk:"node_pools"`
|
||||||
Maintenance types.Object `tfsdk:"maintenance"`
|
Maintenance types.Object `tfsdk:"maintenance"`
|
||||||
Hibernations []Hibernation `tfsdk:"hibernations"`
|
Hibernations types.List `tfsdk:"hibernations"`
|
||||||
Extensions *Extensions `tfsdk:"extensions"`
|
Extensions *Extensions `tfsdk:"extensions"`
|
||||||
KubeConfig types.String `tfsdk:"kube_config"`
|
KubeConfig types.String `tfsdk:"kube_config"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type NodePool struct {
|
// Struct corresponding to Cluster.NodePools[i]
|
||||||
|
type nodePool struct {
|
||||||
Name types.String `tfsdk:"name"`
|
Name types.String `tfsdk:"name"`
|
||||||
MachineType types.String `tfsdk:"machine_type"`
|
MachineType types.String `tfsdk:"machine_type"`
|
||||||
OSName types.String `tfsdk:"os_name"`
|
OSName types.String `tfsdk:"os_name"`
|
||||||
|
|
@ -79,17 +80,44 @@ type NodePool struct {
|
||||||
VolumeType types.String `tfsdk:"volume_type"`
|
VolumeType types.String `tfsdk:"volume_type"`
|
||||||
VolumeSize types.Int64 `tfsdk:"volume_size"`
|
VolumeSize types.Int64 `tfsdk:"volume_size"`
|
||||||
Labels types.Map `tfsdk:"labels"`
|
Labels types.Map `tfsdk:"labels"`
|
||||||
Taints []Taint `tfsdk:"taints"`
|
Taints types.List `tfsdk:"taints"`
|
||||||
CRI types.String `tfsdk:"cri"`
|
CRI types.String `tfsdk:"cri"`
|
||||||
AvailabilityZones types.List `tfsdk:"availability_zones"`
|
AvailabilityZones types.List `tfsdk:"availability_zones"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Taint struct {
|
// Types corresponding to odePool
|
||||||
|
var nodePoolTypes = map[string]attr.Type{
|
||||||
|
"name": basetypes.StringType{},
|
||||||
|
"machine_type": basetypes.StringType{},
|
||||||
|
"os_name": basetypes.StringType{},
|
||||||
|
"os_version": basetypes.StringType{},
|
||||||
|
"minimum": basetypes.Int64Type{},
|
||||||
|
"maximum": basetypes.Int64Type{},
|
||||||
|
"max_surge": basetypes.Int64Type{},
|
||||||
|
"max_unavailable": basetypes.Int64Type{},
|
||||||
|
"volume_type": basetypes.StringType{},
|
||||||
|
"volume_size": basetypes.Int64Type{},
|
||||||
|
"labels": basetypes.MapType{ElemType: types.StringType},
|
||||||
|
"taints": basetypes.ListType{ElemType: types.ObjectType{AttrTypes: taintTypes}},
|
||||||
|
"cri": basetypes.StringType{},
|
||||||
|
"availability_zones": basetypes.ListType{ElemType: types.StringType},
|
||||||
|
}
|
||||||
|
|
||||||
|
// Struct corresponding to nodePool.Taints[i]
|
||||||
|
type taint struct {
|
||||||
Effect types.String `tfsdk:"effect"`
|
Effect types.String `tfsdk:"effect"`
|
||||||
Key types.String `tfsdk:"key"`
|
Key types.String `tfsdk:"key"`
|
||||||
Value types.String `tfsdk:"value"`
|
Value types.String `tfsdk:"value"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Types corresponding to taint
|
||||||
|
var taintTypes = map[string]attr.Type{
|
||||||
|
"effect": basetypes.StringType{},
|
||||||
|
"key": basetypes.StringType{},
|
||||||
|
"value": basetypes.StringType{},
|
||||||
|
}
|
||||||
|
|
||||||
|
// Struct corresponding to Cluster.Maintenance
|
||||||
type Maintenance struct {
|
type Maintenance struct {
|
||||||
EnableKubernetesVersionUpdates types.Bool `tfsdk:"enable_kubernetes_version_updates"`
|
EnableKubernetesVersionUpdates types.Bool `tfsdk:"enable_kubernetes_version_updates"`
|
||||||
EnableMachineImageVersionUpdates types.Bool `tfsdk:"enable_machine_image_version_updates"`
|
EnableMachineImageVersionUpdates types.Bool `tfsdk:"enable_machine_image_version_updates"`
|
||||||
|
|
@ -97,6 +125,7 @@ type Maintenance struct {
|
||||||
End types.String `tfsdk:"end"`
|
End types.String `tfsdk:"end"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Types corresponding to Maintenance
|
||||||
var maintenanceTypes = map[string]attr.Type{
|
var maintenanceTypes = map[string]attr.Type{
|
||||||
"enable_kubernetes_version_updates": basetypes.BoolType{},
|
"enable_kubernetes_version_updates": basetypes.BoolType{},
|
||||||
"enable_machine_image_version_updates": basetypes.BoolType{},
|
"enable_machine_image_version_updates": basetypes.BoolType{},
|
||||||
|
|
@ -104,12 +133,20 @@ var maintenanceTypes = map[string]attr.Type{
|
||||||
"end": basetypes.StringType{},
|
"end": basetypes.StringType{},
|
||||||
}
|
}
|
||||||
|
|
||||||
type Hibernation struct {
|
// Struct corresponding to Cluster.Hibernations[i]
|
||||||
|
type hibernation struct {
|
||||||
Start types.String `tfsdk:"start"`
|
Start types.String `tfsdk:"start"`
|
||||||
End types.String `tfsdk:"end"`
|
End types.String `tfsdk:"end"`
|
||||||
Timezone types.String `tfsdk:"timezone"`
|
Timezone types.String `tfsdk:"timezone"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Types corresponding to hibernation
|
||||||
|
var hibernationTypes = map[string]attr.Type{
|
||||||
|
"start": basetypes.StringType{},
|
||||||
|
"end": basetypes.StringType{},
|
||||||
|
"timezone": basetypes.StringType{},
|
||||||
|
}
|
||||||
|
|
||||||
type Extensions struct {
|
type Extensions struct {
|
||||||
Argus *ArgusExtension `tfsdk:"argus"`
|
Argus *ArgusExtension `tfsdk:"argus"`
|
||||||
ACL *ACL `tfsdk:"acl"`
|
ACL *ACL `tfsdk:"acl"`
|
||||||
|
|
@ -549,13 +586,21 @@ func (r *clusterResource) createOrUpdateCluster(ctx context.Context, diags *diag
|
||||||
if hasDeprecatedVersion {
|
if hasDeprecatedVersion {
|
||||||
diags.AddWarning("Deprecated Kubernetes version", fmt.Sprintf("Version %s of Kubernetes is deprecated, please update it", *kubernetes.Version))
|
diags.AddWarning("Deprecated Kubernetes version", fmt.Sprintf("Version %s of Kubernetes is deprecated, please update it", *kubernetes.Version))
|
||||||
}
|
}
|
||||||
nodePools := toNodepoolsPayload(ctx, model)
|
nodePools, err := toNodepoolsPayload(ctx, model)
|
||||||
|
if err != nil {
|
||||||
|
core.LogAndAddError(ctx, diags, "Error creating/updating cluster", fmt.Sprintf("Creating node pools API payload: %v", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
maintenance, err := toMaintenancePayload(ctx, model)
|
maintenance, err := toMaintenancePayload(ctx, model)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
core.LogAndAddError(ctx, diags, "Error creating/updating cluster", fmt.Sprintf("Creating maintenance API payload: %v", err))
|
core.LogAndAddError(ctx, diags, "Error creating/updating cluster", fmt.Sprintf("Creating maintenance API payload: %v", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
hibernations := toHibernationsPayload(model)
|
hibernations, err := toHibernationsPayload(ctx, model)
|
||||||
|
if err != nil {
|
||||||
|
core.LogAndAddError(ctx, diags, "Error creating/updating cluster", fmt.Sprintf("Creating hibernations API payload: %v", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
extensions, err := toExtensionsPayload(ctx, model)
|
extensions, err := toExtensionsPayload(ctx, model)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
core.LogAndAddError(ctx, diags, "Error creating/updating cluster", fmt.Sprintf("Creating extension API payload: %v", err))
|
core.LogAndAddError(ctx, diags, "Error creating/updating cluster", fmt.Sprintf("Creating extension API payload: %v", err))
|
||||||
|
|
@ -608,13 +653,26 @@ func (r *clusterResource) getCredential(ctx context.Context, model *Cluster) err
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func toNodepoolsPayload(ctx context.Context, m *Cluster) []ske.Nodepool {
|
func toNodepoolsPayload(ctx context.Context, m *Cluster) ([]ske.Nodepool, error) {
|
||||||
|
nodePools := []nodePool{}
|
||||||
|
diags := m.NodePools.ElementsAs(ctx, &nodePools, false)
|
||||||
|
if diags.HasError() {
|
||||||
|
return nil, core.DiagsToError(diags)
|
||||||
|
}
|
||||||
|
|
||||||
cnps := []ske.Nodepool{}
|
cnps := []ske.Nodepool{}
|
||||||
for i := range m.NodePools {
|
for i := range nodePools {
|
||||||
|
nodePool := nodePools[i]
|
||||||
|
|
||||||
// taints
|
// taints
|
||||||
|
taintsModel := []taint{}
|
||||||
|
diags := nodePool.Taints.ElementsAs(ctx, &taintsModel, false)
|
||||||
|
if diags.HasError() {
|
||||||
|
return nil, core.DiagsToError(diags)
|
||||||
|
}
|
||||||
|
|
||||||
ts := []ske.Taint{}
|
ts := []ske.Taint{}
|
||||||
nodePool := m.NodePools[i]
|
for _, v := range taintsModel {
|
||||||
for _, v := range nodePool.Taints {
|
|
||||||
t := ske.Taint{
|
t := ske.Taint{
|
||||||
Effect: v.Effect.ValueStringPointer(),
|
Effect: v.Effect.ValueStringPointer(),
|
||||||
Key: v.Key.ValueStringPointer(),
|
Key: v.Key.ValueStringPointer(),
|
||||||
|
|
@ -680,12 +738,22 @@ func toNodepoolsPayload(ctx context.Context, m *Cluster) []ske.Nodepool {
|
||||||
}
|
}
|
||||||
cnps = append(cnps, cnp)
|
cnps = append(cnps, cnp)
|
||||||
}
|
}
|
||||||
return cnps
|
return cnps, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func toHibernationsPayload(m *Cluster) *ske.Hibernation {
|
func toHibernationsPayload(ctx context.Context, m *Cluster) (*ske.Hibernation, error) {
|
||||||
|
hibernation := []hibernation{}
|
||||||
|
diags := m.Hibernations.ElementsAs(ctx, &hibernation, false)
|
||||||
|
if diags.HasError() {
|
||||||
|
return nil, core.DiagsToError(diags)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(hibernation) == 0 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
scs := []ske.HibernationSchedule{}
|
scs := []ske.HibernationSchedule{}
|
||||||
for _, h := range m.Hibernations {
|
for _, h := range hibernation {
|
||||||
sc := ske.HibernationSchedule{
|
sc := ske.HibernationSchedule{
|
||||||
Start: h.Start.ValueStringPointer(),
|
Start: h.Start.ValueStringPointer(),
|
||||||
End: h.End.ValueStringPointer(),
|
End: h.End.ValueStringPointer(),
|
||||||
|
|
@ -697,13 +765,9 @@ func toHibernationsPayload(m *Cluster) *ske.Hibernation {
|
||||||
scs = append(scs, sc)
|
scs = append(scs, sc)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(scs) == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return &ske.Hibernation{
|
return &ske.Hibernation{
|
||||||
Schedules: &scs,
|
Schedules: &scs,
|
||||||
}
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func toExtensionsPayload(ctx context.Context, m *Cluster) (*ske.Extension, error) {
|
func toExtensionsPayload(ctx context.Context, m *Cluster) (*ske.Extension, error) {
|
||||||
|
|
@ -805,104 +869,167 @@ func mapFields(ctx context.Context, cl *ske.ClusterResponse, m *Cluster) error {
|
||||||
m.KubernetesVersionUsed = types.StringPointerValue(cl.Kubernetes.Version)
|
m.KubernetesVersionUsed = types.StringPointerValue(cl.Kubernetes.Version)
|
||||||
m.AllowPrivilegedContainers = types.BoolPointerValue(cl.Kubernetes.AllowPrivilegedContainers)
|
m.AllowPrivilegedContainers = types.BoolPointerValue(cl.Kubernetes.AllowPrivilegedContainers)
|
||||||
}
|
}
|
||||||
if cl.Nodepools == nil {
|
|
||||||
m.NodePools = []NodePool{}
|
|
||||||
} else {
|
|
||||||
nodepools := *cl.Nodepools
|
|
||||||
m.NodePools = []NodePool{}
|
|
||||||
for i := range nodepools {
|
|
||||||
np := nodepools[i]
|
|
||||||
|
|
||||||
maimna := types.StringNull()
|
err := mapNodePools(cl, m)
|
||||||
maimver := types.StringNull()
|
|
||||||
if np.Machine != nil && np.Machine.Image != nil {
|
|
||||||
maimna = types.StringPointerValue(np.Machine.Image.Name)
|
|
||||||
maimver = types.StringPointerValue(np.Machine.Image.Version)
|
|
||||||
}
|
|
||||||
vt := types.StringNull()
|
|
||||||
if np.Volume != nil {
|
|
||||||
vt = types.StringPointerValue(np.Volume.Type)
|
|
||||||
}
|
|
||||||
crin := types.StringNull()
|
|
||||||
if np.Cri != nil {
|
|
||||||
crin = types.StringPointerValue(np.Cri.Name)
|
|
||||||
}
|
|
||||||
n := NodePool{
|
|
||||||
Name: types.StringPointerValue(np.Name),
|
|
||||||
MachineType: types.StringPointerValue(np.Machine.Type),
|
|
||||||
OSName: maimna,
|
|
||||||
OSVersion: maimver,
|
|
||||||
Minimum: types.Int64PointerValue(np.Minimum),
|
|
||||||
Maximum: types.Int64PointerValue(np.Maximum),
|
|
||||||
MaxSurge: types.Int64PointerValue(np.MaxSurge),
|
|
||||||
MaxUnavailable: types.Int64PointerValue(np.MaxUnavailable),
|
|
||||||
VolumeType: vt,
|
|
||||||
VolumeSize: types.Int64PointerValue(np.Volume.Size),
|
|
||||||
Labels: types.MapNull(types.StringType),
|
|
||||||
Taints: nil,
|
|
||||||
CRI: crin,
|
|
||||||
AvailabilityZones: types.ListNull(types.StringType),
|
|
||||||
}
|
|
||||||
if np.Labels != nil {
|
|
||||||
elems := map[string]attr.Value{}
|
|
||||||
for k, v := range *np.Labels {
|
|
||||||
elems[k] = types.StringValue(v)
|
|
||||||
}
|
|
||||||
n.Labels = types.MapValueMust(types.StringType, elems)
|
|
||||||
}
|
|
||||||
if np.Taints != nil {
|
|
||||||
for _, v := range *np.Taints {
|
|
||||||
if n.Taints == nil {
|
|
||||||
n.Taints = []Taint{}
|
|
||||||
}
|
|
||||||
n.Taints = append(n.Taints, Taint{
|
|
||||||
Effect: types.StringPointerValue(v.Effect),
|
|
||||||
Key: types.StringPointerValue(v.Key),
|
|
||||||
Value: types.StringPointerValue(v.Value),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if np.AvailabilityZones == nil {
|
|
||||||
n.AvailabilityZones = types.ListNull(types.StringType)
|
|
||||||
} else {
|
|
||||||
elems := []attr.Value{}
|
|
||||||
for _, v := range *np.AvailabilityZones {
|
|
||||||
elems = append(elems, types.StringValue(v))
|
|
||||||
}
|
|
||||||
n.AvailabilityZones = types.ListValueMust(types.StringType, elems)
|
|
||||||
}
|
|
||||||
m.NodePools = append(m.NodePools, n)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
err := mapMaintenance(ctx, cl, m)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return fmt.Errorf("mapping node_pools: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = mapMaintenance(ctx, cl, m)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("mapping maintenance: %w", err)
|
||||||
|
}
|
||||||
|
err = mapHibernations(cl, m)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("mapping hibernations: %w", err)
|
||||||
}
|
}
|
||||||
mapHibernations(cl, m)
|
|
||||||
mapExtensions(cl, m)
|
mapExtensions(cl, m)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func mapHibernations(cl *ske.ClusterResponse, m *Cluster) {
|
func mapNodePools(cl *ske.ClusterResponse, m *Cluster) error {
|
||||||
if cl.Hibernation == nil || cl.Hibernation.Schedules == nil {
|
if cl.Nodepools == nil {
|
||||||
return
|
m.NodePools = types.ListNull(types.ObjectType{AttrTypes: nodePoolTypes})
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
m.Hibernations = []Hibernation{}
|
nodePools := []attr.Value{}
|
||||||
for _, h := range *cl.Hibernation.Schedules {
|
for i, nodePoolResp := range *cl.Nodepools {
|
||||||
m.Hibernations = append(m.Hibernations, Hibernation{
|
nodePool := map[string]attr.Value{
|
||||||
Start: types.StringPointerValue(h.Start),
|
"name": types.StringPointerValue(nodePoolResp.Name),
|
||||||
End: types.StringPointerValue(h.End),
|
"machine_type": types.StringPointerValue(nodePoolResp.Machine.Type),
|
||||||
Timezone: types.StringPointerValue(h.Timezone),
|
"os_name": types.StringNull(),
|
||||||
})
|
"os_version": types.StringNull(),
|
||||||
|
"minimum": types.Int64PointerValue(nodePoolResp.Minimum),
|
||||||
|
"maximum": types.Int64PointerValue(nodePoolResp.Maximum),
|
||||||
|
"max_surge": types.Int64PointerValue(nodePoolResp.MaxSurge),
|
||||||
|
"max_unavailable": types.Int64PointerValue(nodePoolResp.MaxUnavailable),
|
||||||
|
"volume_type": types.StringNull(),
|
||||||
|
"volume_size": types.Int64PointerValue(nodePoolResp.Volume.Size),
|
||||||
|
"labels": types.MapNull(types.StringType),
|
||||||
|
"cri": types.StringNull(),
|
||||||
|
"availability_zones": types.ListNull(types.StringType),
|
||||||
|
}
|
||||||
|
|
||||||
|
if nodePoolResp.Machine != nil && nodePoolResp.Machine.Image != nil {
|
||||||
|
nodePool["os_name"] = types.StringPointerValue(nodePoolResp.Machine.Image.Name)
|
||||||
|
nodePool["os_version"] = types.StringPointerValue(nodePoolResp.Machine.Image.Version)
|
||||||
|
}
|
||||||
|
|
||||||
|
if nodePoolResp.Volume != nil {
|
||||||
|
nodePool["volume_type"] = types.StringPointerValue(nodePoolResp.Volume.Type)
|
||||||
|
}
|
||||||
|
|
||||||
|
if nodePoolResp.Cri != nil {
|
||||||
|
nodePool["cri"] = types.StringPointerValue(nodePoolResp.Cri.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
err := mapTaints(nodePoolResp.Taints, nodePool)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("mapping index %d, field taints: %w", i, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if nodePoolResp.Labels != nil {
|
||||||
|
elems := map[string]attr.Value{}
|
||||||
|
for k, v := range *nodePoolResp.Labels {
|
||||||
|
elems[k] = types.StringValue(v)
|
||||||
|
}
|
||||||
|
elemsTF, diags := types.MapValue(types.StringType, elems)
|
||||||
|
if diags.HasError() {
|
||||||
|
return fmt.Errorf("mapping index %d, field labels: %w", i, core.DiagsToError(diags))
|
||||||
|
}
|
||||||
|
nodePool["labels"] = elemsTF
|
||||||
|
}
|
||||||
|
|
||||||
|
if nodePoolResp.AvailabilityZones != nil {
|
||||||
|
elems := []attr.Value{}
|
||||||
|
for _, v := range *nodePoolResp.AvailabilityZones {
|
||||||
|
elems = append(elems, types.StringValue(v))
|
||||||
|
}
|
||||||
|
elemsTF, diags := types.ListValue(types.StringType, elems)
|
||||||
|
if diags.HasError() {
|
||||||
|
return fmt.Errorf("mapping index %d, field availability_zones: %w", i, core.DiagsToError(diags))
|
||||||
|
}
|
||||||
|
nodePool["availability_zones"] = elemsTF
|
||||||
|
}
|
||||||
|
|
||||||
|
nodePoolTF, diags := basetypes.NewObjectValue(nodePoolTypes, nodePool)
|
||||||
|
if diags.HasError() {
|
||||||
|
return fmt.Errorf("mapping index %d: %w", i, core.DiagsToError(diags))
|
||||||
|
}
|
||||||
|
nodePools = append(nodePools, nodePoolTF)
|
||||||
}
|
}
|
||||||
|
nodePoolsTF, diags := basetypes.NewListValue(types.ObjectType{AttrTypes: nodePoolTypes}, nodePools)
|
||||||
|
if diags.HasError() {
|
||||||
|
return core.DiagsToError(diags)
|
||||||
|
}
|
||||||
|
m.NodePools = nodePoolsTF
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func mapTaints(t *[]ske.Taint, nodePool map[string]attr.Value) error {
|
||||||
|
if t == nil || len(*t) == 0 {
|
||||||
|
nodePool["taints"] = types.ListNull(types.ObjectType{AttrTypes: taintTypes})
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
taints := []attr.Value{}
|
||||||
|
|
||||||
|
for i, taintResp := range *t {
|
||||||
|
taint := map[string]attr.Value{
|
||||||
|
"effect": types.StringPointerValue(taintResp.Effect),
|
||||||
|
"key": types.StringPointerValue(taintResp.Key),
|
||||||
|
"value": types.StringPointerValue(taintResp.Value),
|
||||||
|
}
|
||||||
|
taintTF, diags := basetypes.NewObjectValue(taintTypes, taint)
|
||||||
|
if diags.HasError() {
|
||||||
|
return fmt.Errorf("mapping index %d: %w", i, core.DiagsToError(diags))
|
||||||
|
}
|
||||||
|
taints = append(taints, taintTF)
|
||||||
|
}
|
||||||
|
|
||||||
|
taintsTF, diags := basetypes.NewListValue(types.ObjectType{AttrTypes: taintTypes}, taints)
|
||||||
|
if diags.HasError() {
|
||||||
|
return core.DiagsToError(diags)
|
||||||
|
}
|
||||||
|
|
||||||
|
nodePool["taints"] = taintsTF
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func mapHibernations(cl *ske.ClusterResponse, m *Cluster) error {
|
||||||
|
if cl.Hibernation == nil || cl.Hibernation.Schedules == nil {
|
||||||
|
m.Hibernations = basetypes.NewListNull(basetypes.ObjectType{AttrTypes: hibernationTypes})
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
hibernations := []attr.Value{}
|
||||||
|
for i, hibernationResp := range *cl.Hibernation.Schedules {
|
||||||
|
hibernation := map[string]attr.Value{
|
||||||
|
"start": types.StringPointerValue(hibernationResp.Start),
|
||||||
|
"end": types.StringPointerValue(hibernationResp.End),
|
||||||
|
"timezone": types.StringPointerValue(hibernationResp.Timezone),
|
||||||
|
}
|
||||||
|
hibernationTF, diags := basetypes.NewObjectValue(hibernationTypes, hibernation)
|
||||||
|
if diags.HasError() {
|
||||||
|
return fmt.Errorf("mapping index %d: %w", i, core.DiagsToError(diags))
|
||||||
|
}
|
||||||
|
hibernations = append(hibernations, hibernationTF)
|
||||||
|
}
|
||||||
|
|
||||||
|
hibernationsTF, diags := basetypes.NewListValue(types.ObjectType{AttrTypes: hibernationTypes}, hibernations)
|
||||||
|
if diags.HasError() {
|
||||||
|
return core.DiagsToError(diags)
|
||||||
|
}
|
||||||
|
|
||||||
|
m.Hibernations = hibernationsTF
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func mapMaintenance(ctx context.Context, cl *ske.ClusterResponse, m *Cluster) error {
|
func mapMaintenance(ctx context.Context, cl *ske.ClusterResponse, m *Cluster) error {
|
||||||
// Aligned with SKE team that a flattened data structure is fine, because not extensions are planned.
|
// Aligned with SKE team that a flattened data structure is fine, because not extensions are planned.
|
||||||
if cl.Maintenance == nil {
|
if cl.Maintenance == nil {
|
||||||
m.Maintenance = types.ObjectNull(map[string]attr.Type{})
|
m.Maintenance = types.ObjectNull(maintenanceTypes)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
ekvu := types.BoolNull()
|
ekvu := types.BoolNull()
|
||||||
|
|
|
||||||
|
|
@ -31,9 +31,9 @@ func TestMapFields(t *testing.T) {
|
||||||
Name: types.StringValue("name"),
|
Name: types.StringValue("name"),
|
||||||
KubernetesVersion: types.StringNull(),
|
KubernetesVersion: types.StringNull(),
|
||||||
AllowPrivilegedContainers: types.BoolNull(),
|
AllowPrivilegedContainers: types.BoolNull(),
|
||||||
NodePools: []NodePool{},
|
NodePools: types.ListNull(types.ObjectType{AttrTypes: nodePoolTypes}),
|
||||||
Maintenance: types.ObjectNull(map[string]attr.Type{}),
|
Maintenance: types.ObjectNull(maintenanceTypes),
|
||||||
Hibernations: nil,
|
Hibernations: types.ListNull(types.ObjectType{AttrTypes: hibernationTypes}),
|
||||||
Extensions: nil,
|
Extensions: nil,
|
||||||
KubeConfig: types.StringNull(),
|
KubeConfig: types.StringNull(),
|
||||||
},
|
},
|
||||||
|
|
@ -122,43 +122,72 @@ func TestMapFields(t *testing.T) {
|
||||||
KubernetesVersionUsed: types.StringValue("1.2.3"),
|
KubernetesVersionUsed: types.StringValue("1.2.3"),
|
||||||
AllowPrivilegedContainers: types.BoolValue(true),
|
AllowPrivilegedContainers: types.BoolValue(true),
|
||||||
|
|
||||||
NodePools: []NodePool{
|
NodePools: types.ListValueMust(
|
||||||
{
|
types.ObjectType{AttrTypes: nodePoolTypes},
|
||||||
Name: types.StringValue("node"),
|
[]attr.Value{
|
||||||
MachineType: types.StringValue("B"),
|
types.ObjectValueMust(
|
||||||
OSName: types.StringValue("os"),
|
nodePoolTypes,
|
||||||
OSVersion: types.StringValue("os-ver"),
|
map[string]attr.Value{
|
||||||
Minimum: types.Int64Value(1),
|
"name": types.StringValue("node"),
|
||||||
Maximum: types.Int64Value(5),
|
"machine_type": types.StringValue("B"),
|
||||||
MaxSurge: types.Int64Value(3),
|
"os_name": types.StringValue("os"),
|
||||||
MaxUnavailable: types.Int64Null(),
|
"os_version": types.StringValue("os-ver"),
|
||||||
VolumeType: types.StringValue("type"),
|
"minimum": types.Int64Value(1),
|
||||||
VolumeSize: types.Int64Value(3),
|
"maximum": types.Int64Value(5),
|
||||||
Labels: types.MapValueMust(types.StringType, map[string]attr.Value{"k": types.StringValue("v")}),
|
"max_surge": types.Int64Value(3),
|
||||||
Taints: []Taint{
|
"max_unavailable": types.Int64Null(),
|
||||||
{
|
"volume_type": types.StringValue("type"),
|
||||||
Effect: types.StringValue("effect"),
|
"volume_size": types.Int64Value(3),
|
||||||
Key: types.StringValue("key"),
|
"labels": types.MapValueMust(
|
||||||
Value: types.StringValue("value"),
|
types.StringType,
|
||||||
|
map[string]attr.Value{
|
||||||
|
"k": types.StringValue("v"),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
"taints": types.ListValueMust(
|
||||||
|
types.ObjectType{AttrTypes: taintTypes},
|
||||||
|
[]attr.Value{
|
||||||
|
types.ObjectValueMust(
|
||||||
|
taintTypes,
|
||||||
|
map[string]attr.Value{
|
||||||
|
"effect": types.StringValue("effect"),
|
||||||
|
"key": types.StringValue("key"),
|
||||||
|
"value": types.StringValue("value"),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
"cri": types.StringValue("cri"),
|
||||||
|
"availability_zones": types.ListValueMust(
|
||||||
|
types.StringType,
|
||||||
|
[]attr.Value{
|
||||||
|
types.StringValue("z1"),
|
||||||
|
types.StringValue("z2"),
|
||||||
|
},
|
||||||
|
),
|
||||||
},
|
},
|
||||||
},
|
),
|
||||||
CRI: types.StringValue("cri"),
|
|
||||||
AvailabilityZones: types.ListValueMust(types.StringType, []attr.Value{types.StringValue("z1"), types.StringValue("z2")}),
|
|
||||||
},
|
},
|
||||||
},
|
),
|
||||||
Maintenance: types.ObjectValueMust(maintenanceTypes, map[string]attr.Value{
|
Maintenance: types.ObjectValueMust(maintenanceTypes, map[string]attr.Value{
|
||||||
"enable_kubernetes_version_updates": types.BoolValue(true),
|
"enable_kubernetes_version_updates": types.BoolValue(true),
|
||||||
"enable_machine_image_version_updates": types.BoolValue(true),
|
"enable_machine_image_version_updates": types.BoolValue(true),
|
||||||
"start": types.StringValue("03:04:05+06:00"),
|
"start": types.StringValue("03:04:05+06:00"),
|
||||||
"end": types.StringValue("13:14:15Z"),
|
"end": types.StringValue("13:14:15Z"),
|
||||||
}),
|
}),
|
||||||
Hibernations: []Hibernation{
|
Hibernations: types.ListValueMust(
|
||||||
{
|
types.ObjectType{AttrTypes: hibernationTypes},
|
||||||
Start: types.StringValue("1"),
|
[]attr.Value{
|
||||||
End: types.StringValue("2"),
|
types.ObjectValueMust(
|
||||||
Timezone: types.StringValue("CET"),
|
hibernationTypes,
|
||||||
|
map[string]attr.Value{
|
||||||
|
"start": types.StringValue("1"),
|
||||||
|
"end": types.StringValue("2"),
|
||||||
|
"timezone": types.StringValue("CET"),
|
||||||
|
},
|
||||||
|
),
|
||||||
},
|
},
|
||||||
},
|
),
|
||||||
Extensions: &Extensions{
|
Extensions: &Extensions{
|
||||||
Argus: &ArgusExtension{
|
Argus: &ArgusExtension{
|
||||||
Enabled: types.BoolValue(true),
|
Enabled: types.BoolValue(true),
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ var clusterResource = map[string]string{
|
||||||
"kubernetes_version": "1.24",
|
"kubernetes_version": "1.24",
|
||||||
"kubernetes_version_used": "1.24.17",
|
"kubernetes_version_used": "1.24.17",
|
||||||
"kubernetes_version_new": "1.25",
|
"kubernetes_version_new": "1.25",
|
||||||
"kubernetes_version_used_new": "1.25.14",
|
"kubernetes_version_used_new": "1.25.15",
|
||||||
"allowPrivilegedContainers": "true",
|
"allowPrivilegedContainers": "true",
|
||||||
"nodepool_name": "np-acc-test",
|
"nodepool_name": "np-acc-test",
|
||||||
"nodepool_name_min": "np-acc-min-test",
|
"nodepool_name_min": "np-acc-min-test",
|
||||||
|
|
@ -142,6 +142,7 @@ func getConfig(version string, apc *bool, maintenanceEnd *string) string {
|
||||||
os_version = "%s"
|
os_version = "%s"
|
||||||
minimum = "%s"
|
minimum = "%s"
|
||||||
maximum = "%s"
|
maximum = "%s"
|
||||||
|
max_surge = "%s"
|
||||||
availability_zones = ["%s"]
|
availability_zones = ["%s"]
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
|
@ -188,6 +189,7 @@ func getConfig(version string, apc *bool, maintenanceEnd *string) string {
|
||||||
clusterResource["nodepool_os_version_min"],
|
clusterResource["nodepool_os_version_min"],
|
||||||
clusterResource["nodepool_minimum"],
|
clusterResource["nodepool_minimum"],
|
||||||
clusterResource["nodepool_maximum"],
|
clusterResource["nodepool_maximum"],
|
||||||
|
clusterResource["nodepool_max_surge"],
|
||||||
clusterResource["nodepool_zone"],
|
clusterResource["nodepool_zone"],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue