Skip to content

Commit

Permalink
Improve the organization of the deployment and the Readme
Browse files Browse the repository at this point in the history
Co-authored-by: Sebastián Vargas <[email protected]>
  • Loading branch information
2 people authored and Alby Hernández committed Mar 1, 2022
1 parent 809e865 commit 6902bfb
Show file tree
Hide file tree
Showing 18 changed files with 77 additions and 39 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ kustomization-build: manifests kustomize kubectl-slice ## Generate the manifests
rm -rf deploy/*
mkdir -p deploy
$(KUSTOMIZE) build config/default > deploy/manifests.yaml
$(KUBECTL_SLICE) --input-file=deploy/manifests.yaml --output-dir=deploy
@rm deploy/manifests.yaml deploy/kustomization.yaml || true
cd deploy && $(KUSTOMIZE) create --autodetect
$(KUBECTL_SLICE) --input-file=deploy/manifests.yaml --output-dir=deploy --template="{{.kind|lower}}/{{.metadata.name|dottodash}}.yaml"
@rm deploy/manifests.yaml || true
cd deploy && $(KUSTOMIZE) create --autodetect --recursive

##@ Deployment

Expand Down
70 changes: 54 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,32 +40,59 @@ the tag of the version you want to deploy as follows:
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- https://github.com/prosimcorp/replika//manifests/?ref=main
- https://github.com/prosimcorp/replika//deploy/?ref=main
```
## RBAC
We designed the operator to be able to replicate any kind of resource in a Kubernetes cluster, but by design, Kubernetes
permissions are always only additive. This means that we had to grant only some resources to be replicated by default,
such as Secrets and ConfigMaps. But you can grant other kind of resources just patching a role in our deployment manifests
as follows:
such as Secrets and ConfigMaps. But you can replicate other kind of resources just granting some permissions to the
ServiceAccount of the controller as follows:
```yaml
# clusterRole-replika-custom-resources.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: replika-custom-resources
rules:
- apiGroups:
- ""
resources:
- AlertmanagerConfigs
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
---
# clusterRoleBinding-replika-custom-resources.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: replika-custom-resources
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: replika-custom-resources
subjects:
- kind: ServiceAccount
name: replika-controller-manager
namespace: replika
---
# kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- https://github.com/prosimcorp/replika//manifests/?ref=main

patches:
- target:
group: rbac.authorization.k8s.io
version: v1
kind: ClusterRole
name: replika-manager-role
patch: |-
- op: add
path: "/rules/0/resources/-"
value: "AlertmanagerConfig"
- https://github.com/prosimcorp/replika//deploy/?ref=main

# Add your custom resources
- clusterRole-replika-custom-resources.yaml
- clusterRoleBinding-replika-custom-resources.yaml
```
## How to develop
Expand Down Expand Up @@ -129,7 +156,18 @@ the process, the steps are described in the following recipe:
To replicate resources using this operator you will need to create a CR of kind Replika. You can find the spec samples
for all the versions of the resource in the [examples directory](./config/samples)

You may prefer to learn directly from an example, so let's explain it:
You may prefer to learn directly from an example, so let's explain it replicating a ConfigMap resource:

```yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: sample-configmap
data:
example-key: value
```

Now use a Replika CR to replicate this resource across all namespaces, excluding some sensitive ones:

```yaml
apiVersion: replika.prosimcorp.com/v1alpha1
Expand Down
2 changes: 1 addition & 1 deletion config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ kind: Kustomization
images:
- name: controller
newName: prosimcorp/replika
newTag: v0.1.1
newTag: v0.2.0
10 changes: 5 additions & 5 deletions controllers/replika_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ func (r *ReplikaReconciler) Reconcile(ctx context.Context, req ctrl.Request) (re
}

// 2.2 Failed to get the resource, requeue the request
LogErrorf(ctx, err, "Error getting the Replika from the cluster")
LogInfof(ctx, "Error getting the Replika from the cluster")
return result, err
}

// 3. Update the status before the requeue
defer func() {
err = r.Status().Update(ctx, replikaManifest)
if err != nil {
LogErrorf(ctx, err, "Failed to update the condition on replika: %s", req.Name)
LogInfof(ctx, "Failed to update the condition on replika: %s", req.Name)
}
}()

Expand All @@ -88,7 +88,7 @@ func (r *ReplikaReconciler) Reconcile(ctx context.Context, req ctrl.Request) (re
// Delete all created targets
err = r.DeleteTargets(ctx, replikaManifest)
if err != nil {
LogErrorf(ctx, err, "Unable to delete the targets")
LogInfof(ctx, "Unable to delete the targets")
return result, err
}

Expand All @@ -114,14 +114,14 @@ func (r *ReplikaReconciler) Reconcile(ctx context.Context, req ctrl.Request) (re
// 6. The Replika CR already exist: manage the update
err = r.UpdateTargets(ctx, replikaManifest)
if err != nil {
LogErrorf(ctx, err, "Can not update the targets for the Replika: "+replikaManifest.Name)
LogInfof(ctx, "Can not update the targets for the Replika: "+replikaManifest.Name)
return result, err
}

// 7. Schedule periodical request
RequeueTime, err := r.GetSynchronizationTime(replikaManifest)
if err != nil {
LogErrorf(ctx, err, "Can not requeue the Replika: "+replikaManifest.Name)
LogInfof(ctx, "Can not requeue the Replika: "+replikaManifest.Name)
}
result.RequeueAfter = RequeueTime

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ spec:
- --leader-elect
command:
- /manager
image: prosimcorp/replika:v0.1.1
image: prosimcorp/replika:v0.2.0
livenessProbe:
httpGet:
path: /healthz
Expand Down
26 changes: 13 additions & 13 deletions deploy/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- clusterrole-replika-manager-role.yaml
- clusterrole-replika-metrics-reader.yaml
- clusterrole-replika-proxy-role.yaml
- clusterrolebinding-replika-manager-rolebinding.yaml
- clusterrolebinding-replika-proxy-rolebinding.yaml
- configmap-replika-manager-config.yaml
- customresourcedefinition-replikas.replika.prosimcorp.com.yaml
- deployment-replika-controller-manager.yaml
- namespace-replika.yaml
- role-replika-leader-election-role.yaml
- rolebinding-replika-leader-election-rolebinding.yaml
- service-replika-controller-manager-metrics-service.yaml
- serviceaccount-replika-controller-manager.yaml
- clusterrole/replika-manager-role.yaml
- clusterrole/replika-metrics-reader.yaml
- clusterrole/replika-proxy-role.yaml
- clusterrolebinding/replika-manager-rolebinding.yaml
- clusterrolebinding/replika-proxy-rolebinding.yaml
- configmap/replika-manager-config.yaml
- customresourcedefinition/replikas-replika-prosimcorp-com.yaml
- deployment/replika-controller-manager.yaml
- namespace/replika.yaml
- role/replika-leader-election-role.yaml
- rolebinding/replika-leader-election-rolebinding.yaml
- service/replika-controller-manager-metrics-service.yaml
- serviceaccount/replika-controller-manager.yaml
File renamed without changes.

0 comments on commit 6902bfb

Please sign in to comment.