diff --git a/README.md b/README.md index f09d46d..ac7878b 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/api/v1beta1/kafkaschema_types.go b/api/v1beta1/kafkaschema_types.go index bb77918..a3955b5 100644 --- a/api/v1beta1/kafkaschema_types.go +++ b/api/v1beta1/kafkaschema_types.go @@ -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"` } diff --git a/controllers/kafkaschema_controller.go b/controllers/kafkaschema_controller.go index bce5c3f..c90f750 100644 --- a/controllers/kafkaschema_controller.go +++ b/controllers/kafkaschema_controller.go @@ -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 { @@ -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 } @@ -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 @@ -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 diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 6839a8a..6a74964 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -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 diff --git a/kubernetes/crds/crd.yaml b/kubernetes/crds/crd.yaml index af4c61a..fe13022 100644 --- a/kubernetes/crds/crd.yaml +++ b/kubernetes/crds/crd.yaml @@ -37,6 +37,8 @@ spec: properties: autoReconciliation: type: boolean + deletionPolicy: + type: string data: properties: compatibility: diff --git a/kubernetes/templates/deployment.yaml b/kubernetes/templates/deployment.yaml index fa2dd69..6cf52b4 100644 --- a/kubernetes/templates/deployment.yaml +++ b/kubernetes/templates/deployment.yaml @@ -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