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

feat: support namespace isolation policy #268

Merged
merged 8 commits into from
Nov 25, 2024
Merged
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
3 changes: 2 additions & 1 deletion .github/workflows/chart-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ jobs:
diff config/crd/bases/resource.streamnative.io_pulsarsinks.yaml charts/pulsar-resources-operator/crds/resource.streamnative.io_pulsarsinks.yaml && \
diff config/crd/bases/resource.streamnative.io_pulsarsources.yaml charts/pulsar-resources-operator/crds/resource.streamnative.io_pulsarsources.yaml && \
diff config/crd/bases/resource.streamnative.io_pulsarpackages.yaml charts/pulsar-resources-operator/crds/resource.streamnative.io_pulsarpackages.yaml && \
diff config/crd/bases/resource.streamnative.io_pulsartopics.yaml charts/pulsar-resources-operator/crds/resource.streamnative.io_pulsartopics.yaml
diff config/crd/bases/resource.streamnative.io_pulsartopics.yaml charts/pulsar-resources-operator/crds/resource.streamnative.io_pulsartopics.yaml && \
diff config/crd/bases/resource.streamnative.io_pulsarnsisolationpolicies.yaml charts/pulsar-resources-operator/crds/resource.streamnative.io_pulsarnsisolationpolicies.yaml

- name: Set up Helm
uses: azure/setup-helm@v3
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Currently, the Pulsar Resources Operator provides full lifecycle management for
- [Sinks](docs/pulsar_sink.md)
- [Sources](docs/pulsar_source.md)
- [Geo-Replication](docs/pulsar_geo_replication.md)
- [NS-Isolation-Policy](docs/pulsar_ns_isolation_policy.md)

## Lifecycle Management

Expand Down Expand Up @@ -128,6 +129,7 @@ In this tutorial, a Kubernetes namespace called `test` is used for examples, whi
- [PulsarSink](docs/pulsar_sink.md)
- [PulsarSource](docs/pulsar_source.md)
- [PulsarGeoReplication](docs/pulsar_geo_replication.md)
- [NS-Isolation-Policy](docs/pulsar_ns_isolation_policy.md)

# Contributing

Expand Down
10 changes: 10 additions & 0 deletions api/v1alpha1/pulsarnamespace_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,16 @@ type PulsarNamespaceSpec struct {
// Deduplication controls whether to enable message deduplication for the namespace.
// +optional
Deduplication *bool `json:"deduplication,omitempty"`

// BookieAffinityGroup is the name of the namespace isolation policy to apply to the namespace.
BookieAffinityGroup *BookieAffinityGroupData `json:"bookieAffinityGroup,omitempty"`
}

type BookieAffinityGroupData struct {
BookkeeperAffinityGroupPrimary string `json:"bookkeeperAffinityGroupPrimary"`

// +optional
BookkeeperAffinityGroupSecondary string `json:"bookkeeperAffinityGroupSecondary,omitempty"`
}

// PulsarNamespaceStatus defines the observed state of PulsarNamespace
Expand Down
124 changes: 124 additions & 0 deletions api/v1alpha1/pulsarnsisolationpolicy_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
// Copyright 2024 StreamNative
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package v1alpha1

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// PulsarNSIsolationPolicySpec defines the desired state of a Pulsar namespace isolation policy.
// It corresponds to the configuration options available in Pulsar's namespaceIsolationPolicies admin API.
type PulsarNSIsolationPolicySpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

// Name is the policy name
// +kubebuilder:validation:Required
Name string `json:"name"`

// Cluster is the name of the Pulsar Cluster
// +kubebuilder:validation:Required
Cluster string `json:"cluster"`

// ConnectionRef is the reference to the PulsarConnection resource
// used to connect to the Pulsar cluster for this ns-isolation-policy.
ConnectionRef corev1.LocalObjectReference `json:"connectionRef"`

// Namespaces namespaces-regex list
// +kubebuilder:validation:Required
Namespaces []string `json:"namespaces"`

// Primary primary-broker-regex list
// +kubebuilder:validation:Required
Primary []string `json:"primary"`

// Secondary secondary-broker-regex list, optional
// +optional
Secondary []string `json:"secondary,omitempty"`

// AutoFailoverPolicyType auto failover policy type name, only support min_available now
// +kubebuilder:validation:Required
// +kubebuilder:validation:Enum=min_available
AutoFailoverPolicyType AutoFailoverPolicyType `json:"autoFailoverPolicyType"`

// AutoFailoverPolicyParams auto failover policy parameters
// +kubebuilder:validation:Required
AutoFailoverPolicyParams map[string]string `json:"autoFailoverPolicyParams"`
}

type AutoFailoverPolicyType string

const (
MinAvailable AutoFailoverPolicyType = "min_available"
)

// PulsarNSIsolationPolicyStatus defines the observed state of PulsarNSIsolationPolicy
type PulsarNSIsolationPolicyStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file

// ObservedGeneration is the most recent generation observed for this resource.
// It corresponds to the metadata generation, which is updated on mutation by the API Server.
// This field is used to track whether the controller has processed the latest changes.
// +optional
ObservedGeneration int64 `json:"observedGeneration,omitempty"`

// Conditions represent the latest available observations of the ns-isolation-policy's current state.
// It follows the Kubernetes conventions for condition types and status.
// The "Ready" condition type is typically used to indicate the overall status of the ns-isolation-policy.
// +patchMergeKey=type
// +patchStrategy=merge
// +listType=map
// +listMapKey=type
// +optional
Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:resource:categories=pulsar;pulsarres,shortName=pnsip
//+kubebuilder:printcolumn:name="RESOURCE_NAME",type=string,JSONPath=`.spec.name`
//+kubebuilder:printcolumn:name="GENERATION",type=string,JSONPath=`.metadata.generation`
//+kubebuilder:printcolumn:name="OBSERVED_GENERATION",type=string,JSONPath=`.status.observedGeneration`
//+kubebuilder:printcolumn:name="READY",type=string,JSONPath=`.status.conditions[?(@.type=="Ready")].status`

// PulsarNSIsolationPolicy is the Schema for the pulsar ns-isolation-policy API
// It represents a Pulsar NsIsolationPolicy in the Kubernetes cluster and includes both
// the desired state (Spec) and the observed state (Status) of the policy.
type PulsarNSIsolationPolicy struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec PulsarNSIsolationPolicySpec `json:"spec,omitempty"`
Status PulsarNSIsolationPolicyStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// PulsarNSIsolationPolicyList contains a list of PulsarNSIsolationPolicy resources.
// It is used by the Kubernetes API to return multiple PulsarNSIsolationPolicy objects.
type PulsarNSIsolationPolicyList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []PulsarNSIsolationPolicy `json:"items"`
}

func init() {
SchemeBuilder.Register(&PulsarNSIsolationPolicy{}, &PulsarNSIsolationPolicyList{})
}
139 changes: 139 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@ spec:
- destination_storage
- message_age
type: string
bookieAffinityGroup:
description: BookieAffinityGroup is the name of the namespace isolation
policy to apply to the namespace.
properties:
bookkeeperAffinityGroupPrimary:
type: string
bookkeeperAffinityGroupSecondary:
type: string
required:
- bookkeeperAffinityGroupPrimary
type: object
bundles:
description: |-
Bundles specifies the number of bundles to split the namespace into.
Expand Down Expand Up @@ -324,4 +335,4 @@ status:
kind: ""
plural: ""
conditions: null
storedVersions: null
storedVersions: null
Loading
Loading