Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Address reviews
Browse files Browse the repository at this point in the history
Signed-off-by: Sergen Yalçın <yalcinsergen97@gmail.com>
  • Loading branch information
sergenyalcin committed Jan 3, 2022
1 parent 36d6fb3 commit de01a32
Show file tree
Hide file tree
Showing 28 changed files with 78 additions and 124 deletions.
5 changes: 0 additions & 5 deletions apis/cloudplatform/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions apis/cloudplatform/v1alpha1/zz_serviceaccount_terraformed.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions apis/cloudplatform/v1alpha1/zz_serviceaccount_types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions apis/container/v1alpha1/zz_cluster_terraformed.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apis/container/v1alpha1/zz_cluster_types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions apis/container/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions apis/container/v1alpha1/zz_generated.resolvers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions apis/container/v1alpha1/zz_nodepool_terraformed.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apis/container/v1alpha1/zz_nodepool_types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions apis/monitoring/v1alpha1/zz_alertpolicy_terraformed.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions apis/monitoring/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions apis/monitoring/v1alpha1/zz_uptimecheckconfig_terraformed.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions apis/monitoring/v1alpha1/zz_uptimecheckconfig_types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 0 additions & 43 deletions apis/rconfig/config.go

This file was deleted.

12 changes: 8 additions & 4 deletions config/cloudplatform/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package cloudplatform
import (
"github.com/crossplane/terrajet/pkg/config"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

"github.com/crossplane-contrib/provider-jet-gcp/config/common"
)

// Configure configures individual resources by adding custom
Expand Down Expand Up @@ -53,8 +51,14 @@ func Configure(p *config.Provider) {
})
p.AddResourceConfigurator("google_service_account", func(r *config.Resource) {
r.Kind = "ServiceAccount"
r.ExternalName.GetExternalNameFn = common.GetNameFromFullyQualifiedID
r.UseAsync = true
r.ExternalName = config.ExternalName{
SetIdentifierArgumentFn: func(base map[string]interface{}, name string) {
base["account_id"] = name
},
OmittedFields: []string{"account_id"},
GetExternalNameFn: config.IDAsExternalName,
GetIDFn: config.ExternalNameAsID,
}
})
p.AddResourceConfigurator("google_service_account_iam", func(r *config.Resource) {
r.Kind = "ServiceAccountIAM"
Expand Down
17 changes: 17 additions & 0 deletions config/common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package common
import (
"strings"

jresource "github.com/crossplane/terrajet/pkg/resource"
"github.com/pkg/errors"

"github.com/crossplane/crossplane-runtime/pkg/fieldpath"
Expand All @@ -17,6 +18,9 @@ const (
SelfPackagePath = "github.com/crossplane-contrib/provider-jet-gcp/config/common"

errFmtCannotGetFieldAsString = "cannot get the %q field as string"

// ExtractResourceIDFuncPath holds the GCP resource ID extractor func name
ExtractResourceIDFuncPath = "github.com/crossplane-contrib/provider-jet-gcp/config/common.ExtractResourceID()"
)

var (
Expand Down Expand Up @@ -61,3 +65,16 @@ func GetField(mapping map[string]interface{}, field string) (string, error) {
}
return f, nil
}

// ExtractResourceID extracts the value of `spec.atProvider.id`
// from a Terraformed resource. If mr is not a Terraformed
// resource, returns an empty string.
func ExtractResourceID() reference.ExtractValueFn {
return func(mr resource.Managed) string {
tr, ok := mr.(jresource.Terraformed)
if !ok {
return ""
}
return tr.GetID()
}
}
12 changes: 5 additions & 7 deletions config/kubernetes/config.go → config/container/config.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package kubernetes
package container

import (
"context"
"fmt"
"strings"

"github.com/crossplane-contrib/terrajet/pkg/config"
"github.com/crossplane/terrajet/pkg/config"

"github.com/crossplane-contrib/provider-jet-gcp/apis/rconfig"
"github.com/crossplane-contrib/provider-jet-gcp/config/common"
)

Expand Down Expand Up @@ -36,7 +35,6 @@ func Configure(p *config.Provider) {
})

p.AddResourceConfigurator("google_container_node_pool", func(r *config.Resource) {
locationIndex, clusterNameIndex := 3, 5
r.Kind = "NodePool"
r.ExternalName = config.NameAsIdentifier
r.ExternalName.GetExternalNameFn = common.GetNameFromFullyQualifiedID
Expand All @@ -49,13 +47,13 @@ func Configure(p *config.Provider) {
if err != nil {
return "", err
}
location := strings.Split(clusterID, "/")[locationIndex]
cluster := strings.Split(clusterID, "/")[clusterNameIndex]
location := strings.Split(clusterID, "/")[3]
cluster := strings.Split(clusterID, "/")[5]
return fmt.Sprintf("%s/%s/%s/%s", project, location, cluster, externalName), nil
}
r.References["cluster"] = config.Reference{
Type: "Cluster",
Extractor: rconfig.ExtractResourceIDFuncPath,
Extractor: common.ExtractResourceIDFuncPath,
}
r.UseAsync = true
})
Expand Down
4 changes: 2 additions & 2 deletions config/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"github.com/crossplane-contrib/provider-jet-gcp/config/cloudiot"
"github.com/crossplane-contrib/provider-jet-gcp/config/cloudplatform"
"github.com/crossplane-contrib/provider-jet-gcp/config/compute"
"github.com/crossplane-contrib/provider-jet-gcp/config/container"
"github.com/crossplane-contrib/provider-jet-gcp/config/dataflow"
"github.com/crossplane-contrib/provider-jet-gcp/config/dataproc"
"github.com/crossplane-contrib/provider-jet-gcp/config/kubernetes"
"github.com/crossplane-contrib/provider-jet-gcp/config/project"
"github.com/crossplane-contrib/provider-jet-gcp/config/storage"
)
Expand Down Expand Up @@ -81,7 +81,7 @@ func GetProvider() *tjconfig.Provider {
dataproc.Configure,
project.Configure,
storage.Configure,
kubernetes.Configure,
container.Configure,
} {
configure(pc)
}
Expand Down
3 changes: 1 addition & 2 deletions examples/cloudplatform/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
apiVersion: cloudplatform.gcp.jet.crossplane.io/v1alpha1
kind: ServiceAccount
metadata:
name: example
name: example-service-account
spec:
forProvider:
accountId: service-account-id
displayName: Service Account
4 changes: 2 additions & 2 deletions examples/providerconfig/providerconfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ spec:
credentials:
source: Secret
secretRef:
name: gcp-creds
name: example-creds
namespace: crossplane-system
key: creds
key: credentials

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions internal/controller/container/cluster/zz_controller.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit de01a32

Please sign in to comment.