Skip to content
Open
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ spec:
name: testing
schemaSerializer: string
autoReconciliation: true # true = autoUpdate schema, false = for update CR should be re-created (not set => false)
deletionPolicy: soft # if not specified == soft, hard => ?permanent=true, https://docs.confluent.io/platform/current/schema-registry/schema-deletion-guidelines.html#schemaregistry-deletion
terminationProtection: true # true = don't delete resources on CR deletion, false = when CR deleted, deletes all resource: ConfigMap, Schema from registry (not set => false)
data:
configRef: kafka-schema # ConfigMap
Expand Down
1 change: 1 addition & 0 deletions api/v1beta1/kafkaschema_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type KafkaSchemaSpec struct {
Name string `json:"name"`
SchemaSerializer string `json:"schemaSerializer"`
AutoReconciliation bool `json:"autoReconciliation,omitempty"`
DeletionPolicy string `json:"deletionPolicy,omitempty"`
TerminationProtection bool `json:"terminationProtection,omitempty"`
Data KafkaSchemaData `json:"data"`
}
Expand Down
15 changes: 9 additions & 6 deletions controllers/kafkaschema_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func generateSchemaCompatibilityUrl(subject string) (string, error) {
return url.String(), nil
}

func generateSchemaDeletionUrl(subject string) (string, error) {
func generateSchemaDeletionUrl(subject string, deletionPolicy string) (string, error) {
schemaRegistryHost := os.Getenv("SCHEMA_REGISTRY_HOST")
schemaRegistryPort := os.Getenv("SCHEMA_REGISTRY_PORT")
if len(schemaRegistryHost) == 0 || len(schemaRegistryPort) == 0 {
Expand All @@ -90,9 +90,12 @@ func generateSchemaDeletionUrl(subject string) (string, error) {
url.WriteString(schemaRegistryHost)
url.WriteString(":")
url.WriteString(schemaRegistryPort)
url.WriteString("/config/")
url.WriteString("/subjects/")
url.WriteString(subject)
url.WriteString("?permanent=true")

if deletionPolicy == "hard" {
url.WriteString("?permanent=true")
}

return url.String(), nil
}
Expand Down Expand Up @@ -175,12 +178,12 @@ func (r *KafkaSchemaReconciler) Reconcile(ctx context.Context, req ctrl.Request)
return ctrl.Result{}, err
}
log.Info("ConfigMap was deleted: " + schema.Spec.Data.ConfigRef)
keyDeletionUrl, err := generateSchemaDeletionUrl(schemaKey)
keyDeletionUrl, err := generateSchemaDeletionUrl(schemaKey, schema.Spec.DeletionPolicy)
if err != nil {
log.Error(err, "Cannot create deletion url")
return ctrl.Result{}, err
}
valueDeletionUrl, err := generateSchemaDeletionUrl(schemaValue)
valueDeletionUrl, err := generateSchemaDeletionUrl(schemaValue, schema.Spec.DeletionPolicy)
if err != nil {
log.Error(err, "Cannot create deletion url")
return ctrl.Result{}, err
Expand All @@ -195,7 +198,7 @@ func (r *KafkaSchemaReconciler) Reconcile(ctx context.Context, req ctrl.Request)
log.Error(err, "Failed to delete schema value from registry: "+schemaValue)
return ctrl.Result{}, err
}
log.Info("Schema was removed from registry")
log.Info("Schema was removed from registry, deletionPolicy: %s", schema.Spec.DeletionPolicy)
return ctrl.Result{}, nil
}
return ctrl.Result{}, nil
Expand Down
11 changes: 11 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## [0.1.2] - 2024-08-10

### Added
- `deletionPolocy` (optional) to handle soft/hard delete mechanism for schema deletion

### Changed
- Update `DELETE` method to use `subjects/<:subject>` method according to confluent best pracitces

### Fixed
- Syntax error to reference parameters in `helm/deployment.yaml`

## [0.1.1] - 2023-05-17

### Added
Expand Down
2 changes: 2 additions & 0 deletions kubernetes/crds/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ spec:
properties:
autoReconciliation:
type: boolean
deletionPolicy:
type: string
data:
properties:
compatibility:
Expand Down
4 changes: 2 additions & 2 deletions kubernetes/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ spec:
- name: SCHEMA_REGISTRY_PORT
value: "{{ .Values.schemaRegistry.port }}"
- name: SCHEMA_REGISTRY_KEY
value: {{ .Values.schemaRegistry.key }}
value: {{ .Values.schemaRegistry.apiKey }}
- name: SCHEMA_REGISTRY_SECRET
value: {{ .Values.schemaRegistry.secret }}
value: {{ .Values.schemaRegistry.apiSecret }}
ports:
- name: http
containerPort: 65532
Expand Down