Skip to content

Instantly share code, notes, and snippets.

@VineethReddy02
Last active January 17, 2022 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VineethReddy02/159283bd368a710379eaf0f6bd60a40a to your computer and use it in GitHub Desktop.
Save VineethReddy02/159283bd368a710379eaf0f6bd60a40a to your computer and use it in GitHub Desktop.
GSoC Final Submission

Project Abstract

The Postgres Operator is a project to create an open-sourced managed Postgres service for Kubernetes. The Postgres operator manages Postgres clusters on Kubernetes. kubectl plugins enable extending the Kubernetes command-line client kubectl with commands to manage custom resources. The task is to design and implement a plugin for the kubectl postgres command. My project aims to simplify and ease the usage of postgres clusters using the kubectl plugin. As the postgres operator is capable of many features having a kubectl plugin will ease in running the clusters and u nderstanding the resources way better.

Google Summer of Code Proposal

kubectl pg plugin proposal

Contributions made during GSoC application period

zalando/postgres-operator#506

Description

The developed kubectl pg plugin helps in dealing with postgres clusters efficiently and by decreasing the efforts in working with postgresql resources. Usually dealing with custom resource definations is a bit complicated as everythng needs to verfied and updated manually by changing the manifest file. kubectl pg plugin helps in managing the postgres clusters with ease. We can check whether the postgresql CRD is registered in the cluster or not. By this we can go ahead in creating CRD resources without any manual verfication such as state of postgres operator and CRD created by it. Dealing the postgres-operator is challenging when we have multiple operators in different namespaces. I developed a command which shows the current version of postgres-operator in current namespace and also in specified namespace. Though the usual way of creating postgres resources is using kubectl apply command for ease in managing postgres cluster individually we created kubectl pg create cmd specific to postgres resources. The same has been implemented for update as kubectl pg update and for delete as kubectl pg delete.

Demo

asciicast

PR's Raised

All my work is done in a single PR, As my project involves in developing a independent kubectl plugin.

zalando/postgres-operator#579

GSoC weekly tracker

https://github.com/VineethReddy02/GSoC-Kubectl-Plugin-for-Postgres-Operator-tracker/blob/master/README.md

Developed Features:

  1. Check whether the postgres CRD is registered.

kubectl pg check

  1. Create postgres cluster using manifest file

kubectl pg create -f manifest.yaml

  1. Update postgres cluster using manifest file

kubectl pg update -f manifest.yaml

  1. Delete postgres cluster using manifest file

kubectl pg delete -f manifest.yaml

  1. Delete postgres cluster using cluster name

kubectl pg delete cluster

  1. Delete postgres cluster using cluster name in specified namespace

kubectl pg delete cluster -n namespace

  1. List postgres cluster from current namespace

kubectl pg list

  1. List postgres clusters from all namespaces

kubectl pg list -A

  1. Extend volume of an existing cluster

kubectl pg ext-volume 2Gi -c cluster

  1. Scale the number of instances of postgres cluster

kubectl pg scale 10 -c cluster

  1. Add a database and it's owner to a postgres cluster

kubectl pg add-db DB01 -o OWNER -c cluster

  1. Add a user and set of privileges to a postgres-cluster

kubectl pg add-user USER01 -p login,createdb -c cluster

  1. Fetch the logs of the postgres operator

kubectl pg logs -o

  1. Fetch the logs of a random replica for the provided cluster

kubectl pg logs -c cluster

  1. Fetch the logs of master for the provided postgres cluster

kubectl pg logs -c cluster -m

  1. Fetch the logs of specified replica for provided postgres cluster

kubectl pg logs -c cluster -r 3

  1. Connect to shell prompt of a random replica for the provided postgres cluster

kubectl pg connect -c cluster

  1. Connect to shell prompt of master for the provided postgres cluster

kubectl pg connect -c cluster -m

  1. Connect to shell prompt of specified replica for the provided postgres cluster

kubectl pg connect -c cluster -r 2

  1. Connect to psql prompt of random replica for the provided postgres cluster, db-user as current user and db-name as current username

kubectl pg connect -c cluster -p

  1. Connect to psql prompt of random replica with provided postgres cluster, db-user as specified user and db-name as specified user

kubectl pg connect -c cluster -p -u user01

  1. Connect to psql prompt of random replica with provided postgres cluster, db-user as specified user and db-name as specified db-name

kubectl pg connect -c cluster -p -u user01 -d db01

  1. Connect to psql prompt of specified replica for the provided postgres cluster, db-user as current user and db-name as current username

kubectl pg connect -c cluster -p -r 4

  1. Connect to psql prompt of specified replica with provided postgres cluster, db-user as specified user and db-name as specified user

kubectl pg connect -c cluster -p -r 3 -u user01

  1. Connect to psql prompt of specified replica with provided postgres cluster, db-user as specified user and db-name as specified db-name

kubectl pg connect -c cluster -p -r 3 -u user01 -d db01

  1. Connect to psql prompt of master for the provided postgres cluster, db-user as current user and db-name as current username

kubectl pg connect -c cluster -p -m

  1. Connect to psql prompt of master with provided postgres cluster, db-user as specified user and db-name as specified user

kubectl pg connect -c cluster -p -m -u user01

  1. Connect to psql prompt of master with provided postgres cluster, db-user as specified user and db-name as specified db-name

kubectl pg connect -c cluster -p -m -u user01 -d db01

  1. Get the version of kubectl pg plugin and postgres-operator in default namespace

kubectl pg version

  1. Get the version of kubectl pg plugin and postgres-operator in specified namespace

kubectl pg version -n namespace

Pending

  1. Unit test for kubectl pg plugin.
  2. Autocompletion of kubectl pg commands.
  3. Reload operator configmap / CRD without restarting the operator pod(needs postgres operator related changes.)

Results

The above developed features will help in managing postgres resources. With all the developed features we can modify volume size, scale number of instances, create/update databases, create/update users, fetch the operator logs, fetch the logs of the master/replica pods of the cluster, connect to shell prompt and psql prompt of master/replica pods of the cluster.

Total Commits

pick e6869ea kubectl pg check
pick 7d3fb70 removed LICENSE file
pick 8299dbc Update main.go
pick 7bf77b7 changes on code review comments
pick acd5567 vendoring plugin with deps
pick aeb4c57 removing vendore directory
pick b08a6ed Update main.go
pick 7f20d2e create,update,delete postgresql resources
pick 0dcab24 removed hardcoded default namespace and initial list cmd
pick bd95e17 Enhancement to list if No resources found
pick 4a5ec8e add-user, add-db, ext-volume and documention
pick 053f77e enhancements after reviews
pick a3bada9 Update addUser.go
pick ef947bc review enhancements and go fmt
pick 3415d84 enhanced ext-volume
pick 670b62a ext-vol enhancement
pick 00d05cf cleanup
pick 9c0269c implemented scale
pick d4cd786 review enhancements
pick 7ad6df6 removed panic traces and enhanced add-user pg cmd
pick 109d40a scale properties from configmap,operatorConfig
pick c92f2b8 small enhancement in scale
pick 5dad0a0 connect to master & replica
pick c4aa128 enhanced connect
pick 355fd14 addressed review comments
pick 6c76a47 psql prompt & kubectl pg version
pick cc9e7cd altered based on code review comments
pick da848d0 Swicted to Go Modules & removed hardcoded APIVERSION and zalando-incubator imports & added explicit user flag for kubectl pg connect --psql
pick b73abe8 kubectl pg logs & addressed review comments
pick 692ec52 fixed some code review comments & updates scale level labels
pick 72938d9 addressed review comments and bug fixes
pick 80249b9 scale enhancement using patch
pick 64cbb7b Enhanced add-db, add-user, scale & ext-volume commands with patch and Enhanced operator dependent features in fetching the current namespace
pick 9c0e6d5 added some enhancements and fixed some bugs.
pick c4c38df added support for deploying operator using helm
pick 4c5d961 added enhancement for helm deployment validation for operator
pick ffa3901 added enhancement for helm deployment validation for operator
pick bda55c6 fixed the bugs specific to helm deployment in version,logs,connect
pick 186c44a enhanced add-db to create db on owner exists validation
pick 574e253 Enhanced add-user cmd to add previliges in small as well
pick fc6e806 changed to MIT license
pick f9b7ed9 added exapmples of all commands & enhanced psql connect
pick 429ca0d go formatting is done in this commit
pick 00519da bug fix on list cmd
pick f338afc review comments and auto version change on ./build.sh execution
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment