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

Pvcglobaluniqeid #751

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion pkg/resources/kafka/kafka.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type brokerReconcilePriority int
const (
componentName = "kafka"
brokerConfigTemplate = "%s-config"
brokerStorageTemplate = "%s-%d-storage-%d-"
brokerStorageTemplate = "%s-%d-storage-%d"

brokerConfigMapVolumeMount = "broker-config"
kafkaDataVolumeMount = "kafka-data"
Expand Down
2 changes: 1 addition & 1 deletion pkg/resources/kafka/pvc.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (

func (r *Reconciler) pvc(brokerId int32, storageIndex int, storage v1beta1.StorageConfig, _ logr.Logger) runtime.Object {
return &corev1.PersistentVolumeClaim{
ObjectMeta: templates.ObjectMetaWithGeneratedNameAndAnnotations(
ObjectMeta: templates.ObjectMetaWithNameAndAnnotations(
fmt.Sprintf(brokerStorageTemplate, r.KafkaCluster.Name, brokerId, storageIndex),
util.MergeLabels(
kafka.LabelsForKafka(r.KafkaCluster.Name),
Expand Down
26 changes: 26 additions & 0 deletions pkg/resources/templates/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,25 @@ func ObjectMetaWithGeneratedName(namePrefix string, labels map[string]string, cl
}
}

// ObjectMetaWithName returns a metav1.ObjectMeta object with labels, ownerReference and name
func ObjectMetaWithName(name string, labels map[string]string, cluster *v1beta1.KafkaCluster) metav1.ObjectMeta {
return metav1.ObjectMeta{
Name: name,
Namespace: cluster.Namespace,
Labels: ObjectMetaLabels(cluster, labels),
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: cluster.APIVersion,
Kind: cluster.Kind,
Name: cluster.Name,
UID: cluster.UID,
Controller: util.BoolPointer(true),
BlockOwnerDeletion: util.BoolPointer(true),
},
},
}
}

func ObjectMetaLabels(cluster *v1beta1.KafkaCluster, l map[string]string) map[string]string {
if cluster.Spec.PropagateLabels {
return util.MergeLabels(cluster.Labels, l)
Expand All @@ -108,6 +127,13 @@ func ObjectMetaWithGeneratedNameAndAnnotations(namePrefix string, labels map[str
return o
}

// ObjectMetaWithNameAndAnnotations returns a metav1.ObjectMeta object with labels, ownerReference, name and annotations
func ObjectMetaWithNameAndAnnotations(name string, labels map[string]string, annotations map[string]string, cluster *v1beta1.KafkaCluster) metav1.ObjectMeta {
o := ObjectMetaWithName(name, labels, cluster)
o.Annotations = annotations
return o
}

// ObjectMetaClusterScope returns a metav1.ObjectMeta object with labels, ownerReference, name and annotations
func ObjectMetaClusterScope(name string, labels map[string]string, cluster *v1beta1.KafkaCluster) metav1.ObjectMeta {
return metav1.ObjectMeta{
Expand Down