Skip to content

Commit

Permalink
fix error
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangpengcheng committed Nov 22, 2024
1 parent d5a0c78 commit 1d8adcc
Show file tree
Hide file tree
Showing 9 changed files with 205 additions and 1 deletion.
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
1 change: 1 addition & 0 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ resources:
- bases/resource.streamnative.io_pulsarpackages.yaml
- bases/resource.streamnative.io_pulsarsinks.yaml
- bases/resource.streamnative.io_pulsarsources.yaml
- bases/resource.streamnative.io_pulsarnsisolationpolicies.yaml
#+kubebuilder:scaffold:crdkustomizeresource

patchesStrategicMerge:
Expand Down
38 changes: 38 additions & 0 deletions config/rbac/pulsarnsisolationpolicy_editor_role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# 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.

# permissions for end users to edit pulsarconnections.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: pulsarnsisolation-policy-editor-role
rules:
- apiGroups:
- resource.streamnative.io
resources:
- pulsarnsisolationpolicies
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- resource.streamnative.io
resources:
- pulsarnsisolationpolicies/status
verbs:
- get
34 changes: 34 additions & 0 deletions config/rbac/pulsarnsisolationpolicy_viewer_role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 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.

# permissions for end users to edit pulsarconnections.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: pulsarnsisolation-policy-viewer-role
rules:
- apiGroups:
- resource.streamnative.io
resources:
- pulsarnsisolationpolicies
verbs:
- get
- list
- watch
- apiGroups:
- resource.streamnative.io
resources:
- pulsarnsisolationpolicies/status
verbs:
- get
34 changes: 34 additions & 0 deletions config/samples/resource_v1alpha1_pulsarnsisolationpolicy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 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.

apiVersion: resource.streamnative.io/v1alpha1
kind: PulsarNSIsolationPolicy
metadata:
name: test-pulsar-ns-isolation-policy
namespace: test
spec:
name: test-policy
cluster: standalone
connectionRef:
name: test-pulsar-connection
namespaces:
- test-tenant/test-ns
primary:
- test-pulsar-broker-0.*
secondary:
- test-pulsar-broker-1.*
autoFailoverPolicyType: min_available
autoFailoverPolicyParams:
min_limit: "1"
usage_threshold: "80"
2 changes: 2 additions & 0 deletions controllers/connection_ref_mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ func getConnectionRef(object client.Object) *corev1.LocalObjectReference {
return &v.Spec.ConnectionRef
case *pulsarv1alpha1.PulsarPackage:
return &v.Spec.ConnectionRef
case *pulsarv1alpha1.PulsarNSIsolationPolicy:
return &v.Spec.ConnectionRef
default:
return nil
}
Expand Down
11 changes: 11 additions & 0 deletions controllers/pulsarconnection_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,14 @@ func (r *PulsarConnectionReconciler) SetupWithManager(mgr ctrl.Manager, options
}); err != nil {
return err
}
if err := mgr.GetCache().IndexField(context.TODO(), &resourcev1alpha1.PulsarNSIsolationPolicy{}, ".spec.connectionRef.name",
func(object client.Object) []string {
return []string{
object.(*resourcev1alpha1.PulsarNSIsolationPolicy).Spec.ConnectionRef.Name,
}
}); err != nil {
return err
}

return ctrl.NewControllerManagedBy(mgr).
For(&resourcev1alpha1.PulsarConnection{}).
Expand All @@ -237,6 +245,9 @@ func (r *PulsarConnectionReconciler) SetupWithManager(mgr ctrl.Manager, options
Watches(&source.Kind{Type: &resourcev1alpha1.PulsarFunction{}},
handler.EnqueueRequestsFromMapFunc(ConnectionRefMapper),
builder.WithPredicates(predicate.GenerationChangedPredicate{})).
Watches(&source.Kind{Type: &resourcev1alpha1.PulsarNSIsolationPolicy{}},
handler.EnqueueRequestsFromMapFunc(ConnectionRefMapper),
builder.WithPredicates(predicate.GenerationChangedPredicate{})).
Watches(&source.Kind{Type: &resourcev1alpha1.PulsarSink{}},
handler.EnqueueRequestsFromMapFunc(ConnectionRefMapper),
builder.WithPredicates(predicate.GenerationChangedPredicate{})).
Expand Down
81 changes: 81 additions & 0 deletions docs/pulsar_ns_isolation_policy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# PulsarNSIsolationPolicy

## Overview

The `PulsarNSIsolationPolicy` resource defines a ns-isolation-policy in a Pulsar cluster. It allows you to configure namespace isolation policies to limit the set of brokers that can be used for assignment.

## Specifications

| Field | Description | Required |
|----------------------------|------------------------------------------------------------------------------------------------------|----------|
| `name` | The name of the policy. | Yes |
| `connectionRef` | Reference to the PulsarConnection resource used to connect to the Pulsar cluster for this namespace. | Yes |
| `cluster` | The name of the cluster. | Yes |
| `namespaces` | A list of fully qualified namespace name in the format "tenant/namespace". | Yes |
| `primary` | A list of primary-broker-regex. | Yes |
| `secondary` | A list of secondary-broker-regex. | No |
| `autoFailoverPolicyType` | Auto failover policy type name, only support `min_available` now. | Yes |
| `autoFailoverPolicyParams` | A map of auto failover policy parameters. | Yes |


## Create A Pulsar ns-isolation-policy

1. Define a isolation policy named `test-policy` by using the YAML file and save the YAML file `policy.yaml`.
```yaml
apiVersion: resource.streamnative.io/v1alpha1
kind: PulsarNSIsolationPolicy
metadata:
name: test-pulsar-ns-isolation-policy
namespace: test
spec:
name: test-policy
cluster: standalone
connectionRef:
name: test-pulsar-connection
namespaces:
- test-tenant/test-ns
primary:
- test-pulsar-broker-0.*
secondary:
- test-pulsar-broker-1.*
autoFailoverPolicyType: min_available
autoFailoverPolicyParams:
min_limit: "1"
usage_threshold: "80"
```
2. Apply the YAML file to create the ns-isolation-policy.
```shell
kubectl apply -f policy.yaml
```

3. Check the resource status. When column Ready is true, it indicates the resource is created successfully in the pulsar cluster

```shell
kubectl -n test get pulsarnsisolationpolicy.resource.streamnative.io
```

```shell
NAME RESOURCE_NAME GENERATION OBSERVED_GENERATION READY
test-pulsar-ns-isolation-policy test-policy 1 1 True
```

## Update A Pulsar ns-isolation-policy

You can update the ns-isolation-policy by editing the `policy.yaml` file and then applying it again using `kubectl apply -f policy.yaml`. This allows you to modify various settings of the Pulsar ns-isolation-policy.

After applying changes, you can check the status of the update using:

```shell
kubectl -n test get pulsarnsisolationpolicy.resource.streamnative.io
```
The `OBSERVED_GENERATION` should increment, and `READY` should become `True` when the update is complete.

## Delete A Pulsar ns-isolation-policy

To delete a PulsarNSIsolationPolicy resource, use the following kubectl command:

```shell
kubectl -n test delete pulsarnsisolationpolicy.resource.streamnative.io test-pulsar-ns-isolation-policy
```

0 comments on commit 1d8adcc

Please sign in to comment.