{"id":20691108,"url":"https://github.com/mohammadne/sanjagh","last_synced_at":"2025-06-17T12:37:32.661Z","repository":{"id":207961398,"uuid":"720415936","full_name":"mohammadne/sanjagh","owner":"mohammadne","description":"Simple k8s operator to handle deployments","archived":false,"fork":false,"pushed_at":"2023-12-05T05:19:49.000Z","size":163,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-22T17:08:23.994Z","etag":null,"topics":["ansible","helm","kubernetes","kubernetes-operator"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mohammadne.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-11-18T12:22:40.000Z","updated_at":"2023-12-03T14:56:08.000Z","dependencies_parsed_at":"2023-12-05T06:27:30.008Z","dependency_job_id":"dd3653ac-4f87-402a-b33f-fa41e59740db","html_url":"https://github.com/mohammadne/sanjagh","commit_stats":null,"previous_names":["mohammadne/sanjagh"],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/mohammadne/sanjagh","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohammadne%2Fsanjagh","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohammadne%2Fsanjagh/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohammadne%2Fsanjagh/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohammadne%2Fsanjagh/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mohammadne","download_url":"https://codeload.github.com/mohammadne/sanjagh/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohammadne%2Fsanjagh/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260360003,"owners_count":22997406,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansible","helm","kubernetes","kubernetes-operator"],"created_at":"2024-11-16T23:15:18.535Z","updated_at":"2025-06-17T12:37:27.603Z","avatar_url":"https://github.com/mohammadne.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sanjagh 📌\n\n\u003e `Sanjagh` is a Persian word meaning pin which I choose this word because it hooks things together.\n\nSanjagh is a simple k8s operator to handle deployments and aims to demonstrate best practices for how using operators, I tried to keep things as simple as possible and demonstrate how to deploy and structure your operator projects.\n\n## How it works\n\nThis project aims to follow the Kubernetes [Operator pattern](https://kubernetes.io/docs/concepts/extend-kubernetes/operator/).\n\nIt uses [Controllers](https://kubernetes.io/docs/concepts/architecture/controller/),\nwhich provide a reconcile function responsible for synchronizing resources until the desired state is reached on the cluster.\n\n## Getting Started\n\nYou’ll need a Kubernetes cluster to run against. You can use [KIND](https://sigs.k8s.io/kind) to get a local cluster for testing, or run against a remote cluster.\n\n```sh\n# initialize base project\noperator-sdk init --domain=mohammadne.me --project-name=sanjagh --repo=github.com/mohammadne/sanjagh\n\n# https://book.kubebuilder.io/migration/multi-group.html\noperator-sdk edit --multigroup=false\n\n# resource -\u003e generates the api directory\n# controller -\u003e generates the controller directory\noperator-sdk create api --group=apps --version=v1alpha1 --kind=Executer --controller --resource\n\noperator-sdk create webhook --group apps --version v1alpha1 --kind Executer --programmatic-validation\n```\n\n### Modifying the API definitions\n\nIf you are editing the API definitions, generate the manifests such as CRs or CRDs using:\n\n```sh\nmake manifests\n```\n\n**NOTE:** Run `make --help` for more information on all potential `make` targets\n\nMore information can be found via the [Kubebuilder Documentation](https://book.kubebuilder.io/introduction.html)\n\n## Infrastructure Provisioning\n\nI have developed an ansible playbook in order to provision the required infrastructure required for deploying and testing the Sanjagh.\n\nAs we are under sanctions, normally in Iran we have to use proxy servers, the playbook contains 4 roles and in order to run the `proxy` role you have to define your proxy server credentials, also the `docker` role contains proxy server to set which enables us to use it for pulling and pushing images to appropriate registry, and you have to set that variable too.\nalso in the `kind` role which installs the kind binary and sets up the k8s cluster we have to specify server_ip_address variable to be used when provisioning the kubernetes cluster.\n\n## Deployment\n\n1. Install required tools for working with the application, you can refer to [devenv](https://github.com/mohammadne/devenv) repository to install all the mentioned tools as below:\n\n   - Go (+1.19)\n   - kubectl\n   - helm (helm-secret, helm-diff)\n   - helmsman\n   - telepresence\n\n2. Push your operator image to the remote registry\n\n    **NOTE 1:** Make sure to update the operator image in the deployment as well.\n\n    **NOTE 2:** If you are using ghcr registry, you have to get a personal access token from the `Developer Settings` tab of the settings of the github and proceed with [this document](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry).\n\n    ```sh\n    # tag your HEAD\n    git tag v0.1.0-rc1\n\n    # trigger Github CI action automatically and skip the following\n    git push origin v0.1.0-rc1\n\n    # see your version to be deployed to the registry\n    make version\n\n    # build and push your image to the location specified by `IMAGE`\n    # skip this command if you have already triggered the Github CI.\n    make docker-build docker-push\n    ```\n\n3. Put appropriate sops credentials into `~/.config/sops/age/keys.txt`\n\n4. Install CRDs and other related k8s manifests\n\n    ```sh\n    # install the CRDs into the cluster\n    make install\n\n    # install sanjagh dependency charts\n    helm repo add mohammadne https://mohammadne.me/charts/\n    helm dependency build deployments/sanjagh\n\n    # deploy sanjagh to the cluster via the helmsman\n    make deploy\n    ```\n\n5. Undeploy controller\n\n    ```sh\n    # delete the controller from the cluster\n    make undeploy\n\n    # delete the CRDs from the cluster\n    make uninstall\n    ```\n\n## Development\n\n\u003e **NOTE 1:** if you don't have webhook, you don't need to do the `Deployments` section, also you have to skip steps 1, 2, 3 and some part of step 5.\n\u003e\n\u003e **NOTE 2:** you have to build the correct image for webhook and manager images and the webhook deployment should have at least one available replicas in order for telepresence to inject its sidecar container to intercept network traffic.\n\n1. Deactivate the manager from the cluster\n\n    ```sh\n    kubectl scale deployment sanjagh-manager -n operators --replicas=0\n    ```\n\n2. Clone `tls` secrets and put them in appropriate directory.\n\n    ```sh\n    tls_secret=$(kubectl get secrets sanjagh-webhook-tls -n operators -ojson)\n    echo $tls_secret | jq '.data.\"tls.key\"' -r | base64 -d \u003e secrets/tls/key.pem\n    echo $tls_secret | jq '.data.\"tls.crt\"' -r | base64 -d \u003e secrets/tls/crt.pem\n    ```\n\n3. Ensure `telepresence` is installed in your cluster with the same version with your client\n\n    ```sh\n    # make sure consistency (sync) between client and server versions\n    telepresence helm upgrade\n\n    # start telepresence agent\n    telepresence connect\n\n    # intercept api-server traffic into your localhost via injecting side-car container\n    telepresence intercept sanjagh-webhook -n operators --service sanjagh-webhook --port 8443:master\n    ```\n\n4. Install the CRDs into the (local) cluster\n\n    ```sh\n    make install\n    ```\n\n5. Run webhook and manager with appropriate configuration\n\n    ```bash\n    # start webhook server\n    go run main.go webhook\n\n    # start controllers (controller manager)\n    go run main.go manager\n    ```\n\n6. Install sample-executer in your (local) cluster\n\n    ```sh\n    helm upgrade --install sample-executer ./deployments/sample-executer\n    ```\n\n7. Cleaning up\n\n    ```sh\n    helm uninstall sample-executer\n\n    # delete the CRDs from the cluster\n    make uninstall\n    ```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmohammadne%2Fsanjagh","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmohammadne%2Fsanjagh","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmohammadne%2Fsanjagh/lists"}