Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix ipblock and lan continuous update #9

Merged
merged 4 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cluster/test/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ${KUBECTL} -n upbound-system wait --for=condition=Available deployment --all --t

echo "Creating a default provider config..."
cat <<EOF | ${KUBECTL} apply -f -
apiVersion: upjet-ionoscloud.upbound.io/v1beta1
apiVersion: upjet-ionoscloud.ionoscloud.io/v1beta1
kind: ProviderConfig
metadata:
name: default
Expand Down
28 changes: 28 additions & 0 deletions config/common/common.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package common

import (
"errors"
"github.com/crossplane/crossplane-runtime/pkg/fieldpath"
"github.com/crossplane/crossplane-runtime/pkg/reference"
xpresource "github.com/crossplane/crossplane-runtime/pkg/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)

// FirstIPBlockIP returns the first IP of an ipblock to assign to a wireguard gateway
Expand Down Expand Up @@ -73,3 +75,29 @@ func AutoCertificateProviderLocation() reference.ExtractValueFn {
return result
}
}

// IgnoreEmptyDiffForComputed gets a list of fields on which to ignore the diff from terraform. Computed arguments can throw this error when
// the diff is empty. This should probably be solved by the generator
func IgnoreEmptyDiffForComputed(ignoreList []string) func(diff *terraform.InstanceDiff, state *terraform.InstanceState, config *terraform.ResourceConfig) (*terraform.InstanceDiff, error) {
return func(diff *terraform.InstanceDiff, state *terraform.InstanceState, config *terraform.ResourceConfig) (*terraform.InstanceDiff, error) {
// skip diff customization on create
if state == nil || state.Empty() {
return diff, nil
}
if config == nil {
return nil, errors.New("resource config cannot be nil")
}
// skip no diff or destroy diffs
if diff == nil || diff.Empty() || diff.Destroy || diff.Attributes == nil {
return diff, nil
}

for _, key := range ignoreList {
if diff.Attributes[key] != nil && diff.Attributes[key].Old == "" && diff.Attributes[key].New == "" {
delete(diff.Attributes, key)
}
}

return diff, nil
}
}
10 changes: 8 additions & 2 deletions config/compute/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package compute

import "github.com/crossplane/upjet/pkg/config"
import (
"github.com/crossplane/upjet/pkg/config"
"github.com/ionos-cloud/provider-upjet-ionoscloud/config/common"
)

const shortGroupName = "compute"

Expand Down Expand Up @@ -44,6 +47,8 @@ func Configure(p *config.Provider) {
r.References["pcc"] = config.Reference{
TerraformName: "ionoscloud_private_crossconnect",
}
r.TerraformCustomDiff = common.IgnoreEmptyDiffForComputed([]string{"ip_failover.#"})

})

p.AddResourceConfigurator("ionoscloud_nic", func(r *config.Resource) {
Expand Down Expand Up @@ -89,8 +94,9 @@ func Configure(p *config.Provider) {
}
})

p.AddResourceConfigurator("ionoscloud_ipblock", func(r *config.Resource) {
p.AddResourceConfigurator("ionoscloud_ipblock", func(r *config.Resource) { // nolint: gocyclo
r.ShortGroup = shortGroupName
r.TerraformCustomDiff = common.IgnoreEmptyDiffForComputed([]string{"ip_consumers.#"})
})

p.AddResourceConfigurator("ionoscloud_private_crossconnect", func(r *config.Resource) {
Expand Down
File renamed without changes.
19 changes: 19 additions & 0 deletions examples/compute/lan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,26 @@ spec:
matchLabels:
testing.upbound.io/example-name: example
public: false

---

apiVersion: compute.ionoscloud.io/v1alpha1
kind: Datacenter
metadata:
annotations:
meta.upbound.io/example-id: compute/v1alpha1/lan
labels:
testing.upbound.io/example-name: example
name: example
spec:
forProvider:
description: Datacenter Description
location: de/fra
name: example
secAuthProtection: false

---

apiVersion: compute.ionoscloud.io/v1alpha1
kind: Crossconnect
metadata:
Expand Down
16 changes: 0 additions & 16 deletions examples/compute/server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,6 @@ spec:

---

apiVersion: compute.ionoscloud.io/v1alpha1
kind: Ipblock
metadata:
annotations:
meta.upbound.io/example-id: compute/v1alpha1/server
labels:
testing.upbound.io/example-name: example
name: example
spec:
forProvider:
location: us/las
name: IP Block Example
size: 1

---

apiVersion: compute.ionoscloud.io/v1alpha1
kind: Lan
metadata:
Expand Down
14 changes: 1 addition & 13 deletions examples/k8s/nodepool.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,4 @@ spec:
matchLabels:
testing.upbound.io/example-name: example
name: Lan Example
public: false
---
apiVersion: s3.ionoscloud.io/v1alpha1
kind: Bucket
metadata:
annotations:
meta.upbound.io/example-id: s3/v1alpha1/bucket
labels:
testing.upbound.io/example-name: k8s-bucket
name: k8s-bucket
spec:
forProvider:
region: eu-central-3
public: false
10 changes: 0 additions & 10 deletions examples/null/resource.yaml

This file was deleted.

Loading