Skip to content

Commit

Permalink
feat: add kafka topic support
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Schneider committed May 16, 2024
1 parent d80bfb0 commit 5ea258d
Show file tree
Hide file tree
Showing 12 changed files with 443 additions and 3 deletions.
2 changes: 1 addition & 1 deletion apis/confluent/v1alpha1/zz_generated.deepcopy.go

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

1 change: 1 addition & 0 deletions apis/confluent/v1alpha1/zz_generated.resolvers.go

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

84 changes: 84 additions & 0 deletions apis/confluent/v1alpha1/zz_generated_terraformed.go

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

212 changes: 212 additions & 0 deletions apis/confluent/v1alpha1/zz_kafkatopic_types.go

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

1 change: 0 additions & 1 deletion build
Submodule build deleted from 2672ee
48 changes: 48 additions & 0 deletions config/confluent_kafka_topic/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package confluent_kafka_topic

import (
"fmt"

xpref "github.com/crossplane/crossplane-runtime/pkg/reference"
xpresource "github.com/crossplane/crossplane-runtime/pkg/resource"
"github.com/crossplane/upjet/pkg/config"
"github.com/crossplane/upjet/pkg/resource"
)

// Constants for custom Extractor function
var (
selfPackagePath = "github.com/crossplane-contrib/provider-confluent/config/confluent_kafka_topic"
extractResourceIDFn = selfPackagePath + ".ExtractResourceID()"
)

// Configure configures individual resources by adding custom ResourceConfigurators.
func Configure(p *config.Provider) {
p.AddResourceConfigurator("confluent_kafka_topic", func(r *config.Resource) {
// We need to override the default group that upjet generated for
r.ShortGroup = "confluent"
r.UseAsync = true
r.Kind = "KafkaTopic"

// Allows us to reference managedResource ID via spec.forProvider.managedResource.id
r.References["kafka_cluster.id"] = config.Reference{
Type: "Cluster",
}

// Allows us to reference managedResource ID via spec.forProvider.principal.idSelector
r.References["principal"] = config.Reference{
Type: "ServiceAccount",
Extractor: extractResourceIDFn,
}
})
}

func ExtractResourceID() xpref.ExtractValueFn {
return func(mr xpresource.Managed) string {
tr, ok := mr.(resource.Terraformed)
if !ok {
return ""
}

return fmt.Sprintf("User:%v", tr.GetID()) // append 'User:' infront of the service account ID when resolving 'principal' field.
}
}
1 change: 1 addition & 0 deletions config/external_name.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var ExternalNameConfigs = map[string]config.ExternalName{
"confluent_kafka_acl": config.IdentifierFromProvider,
"confluent_role_binding": config.IdentifierFromProvider,
"confluent_schema_registry_cluster": config.IdentifierFromProvider,
"confluent_kafka_topic": config.IdentifierFromProvider,
}

// ExternalNameConfigurations applies all external name configs listed in the
Expand Down
2 changes: 1 addition & 1 deletion config/generated.lst
Original file line number Diff line number Diff line change
@@ -1 +1 @@
["confluent_api_key","confluent_environment","confluent_kafka_acl","confluent_kafka_cluster","confluent_kafka_cluster_config","confluent_role_binding","confluent_schema_registry_cluster","confluent_service_account"]
["confluent_api_key","confluent_environment","confluent_kafka_acl","confluent_kafka_cluster","confluent_kafka_cluster_config","confluent_kafka_topic","confluent_role_binding","confluent_schema_registry_cluster","confluent_service_account"]
Loading

0 comments on commit 5ea258d

Please sign in to comment.