Skip to content

Instantly share code, notes, and snippets.

@zryfish
Last active October 14, 2024 04:45
Show Gist options
  • Select an option

  • Save zryfish/6e8bb8f90eb06a2f4634e1083feb1d1f to your computer and use it in GitHub Desktop.

Select an option

Save zryfish/6e8bb8f90eb06a2f4634e1083feb1d1f to your computer and use it in GitHub Desktop.

Prerequisities

Environment

Reference

Clone repo

export working_dir=$GOPATH/src/kubesphere.io
export user={your github profile name}

$ mkdir -p $working_dir
$ cd $working_dir
$ git clone https://github.com/$user/kubesphere.git
$ cd $working_dir/kubesphere
$ git remote add upstream https://github.com/kubesphere/kubesphere.git

# Never push to upstream master
$ git remote set-url --push upstream no_push

# Confirm your remotes make sense:
$ git remote -v

Code structure

~/go/src/kubesphere.io/kubesphere 
╰─ tree -L 2
.
├── CONTRIBUTING.md
├── LICENSE
├── Makefile
├── OWNERS
├── PROJECT
├── README.md
├── README_zh.md
├── api                 // generated api swagger doc
│   ├── api-rules
│   ├── ks-openapi-spec
│   └── openapi-spec
├── build              // dockerfile 
│   ├── ks-apiserver
│   └── ks-controller-manager
├── cmd                // command line 
│   ├── controller-manager
│   └── ks-apiserver
├── config             // used by code-generator
│   ├── crd
│   ├── crds
│   ├── default
│   ├── manager
│   ├── rbac
│   ├── samples
│   └── webhook
├── doc.go
├── docs
│   ├── images
│   ├── powered-by-kubesphere.md
│   └── roadmap.md
├── go.mod
├── go.sum
├── hack               // scripts to help build ks 
│   ├── boilerplate.go.txt
│   ├── custom-boilerplate.go.txt
│   ├── docker_build.sh
│   ├── generate_certs.sh
│   ├── generate_client.sh
│   ├── generate_group.sh
│   ├── gobuild.sh
│   ├── install_kubebuilder.sh
│   ├── lib
│   ├── lint-dependencies.sh
│   ├── pin-dependency.sh
│   ├── update-vendor-licenses.sh
│   └── update-vendor.sh
├── install         // deprecated
│   ├── ingress-controller
│   ├── scripts
│   └── swagger-ui
├── pkg
│   ├── api          
│   ├── apis         // CRD package
│   ├── apiserver    
│   ├── client       // used by code-generator, informer/lister/clientset
│   ├── constants
│   ├── controller   // controllers
│   ├── db           // deprecated
│   ├── informers    
│   ├── kapis        // KubeSphere specific apis, api path starts with /kapis
│   ├── models       // real business logic       
│   ├── server
│   ├── simple       // client interface with other services, redis/ldap/es/p8s
│   ├── test         
│   ├── tools.go
│   ├── utils
│   ├── version
│   └── webhook
├── test
│   ├── e2e
│   ├── network
│   └── testdata 
├── tools          // used to generate api doc
│   ├── cmd
│   ├── lib
│   └── tools.go

Build KubeSphere

$ make test    // takes a really long time
$ make all     // build ks-apiserver/ks-controller-manager 

$ make ks-apiserver
$ go build -o bin/cmd/ks-apiserver cmd/ks-apiserver/apiserver.go

╭─ ~/go/src/kubesphere.io/kubesphere
╰─ bin/cmd/ks-apiserver  --kubeconfig ~/.kube/config

W1124 20:27:04.397558   75520 options.go:169] ks-apiserver starts without redis provided, it will use in memory cache. This may cause inconsistencies when running ks-apiserver with multiple replicas.
W1124 20:27:04.400550   75520 routers.go:173] open /etc/kubesphere/ingress-controller: no such file or directory
E1124 20:27:04.400569   75520 routers.go:68] error happened during loading external yamls, open /etc/kubesphere/ingress-controller: no such file or directory
I1124 20:27:04.404213   75520 apiserver.go:308] Start cache objects
I1124 20:27:05.039295   75520 apiserver.go:514] Finished caching objects
I1124 20:27:05.039348   75520 apiserver.go:240] Start listening on :9090 

Add your own code

git fetch upstream
git checkout master
git rebase upstream/master  // don't forget to rebase

git checkout -b myfeature

Test

For testing, you use AlwaysAllow mode to skip authorization.

authorization:
  mode: "AlwaysAllow"
curl -v http://[ks-apiserver.kubesphere-system.svc]/kapis/[apiGroup]/[apiVersion]

Test with ks-console

Swap ks-apiserver with local running server, easy for debugging.

sudo telepresence --namespace kubesphere-system --swap-deployment ks-apiserver

For 3.0 and older version

sudo telepresence --namespace kubesphere-system --swap-deployment ks-apiserver --also-proxy redis.kubesphere-system.svc --also-proxy openldap.kubesphere-system.svc

Telepresence alternative kt-connect

Don't forget to quit telepresence after debugging.

Commit your change and make a PR

It's a good practice to create issue first, then assign to yourself before coding.

git add .
git commit -s -m "awesome changes"
git push

Use proper label when create PR, then address the link issue.

Signed-off-by: yuswift yuswiftli@yunify.com

What type of PR is this?

/kind feature

What this PR does / why we need it:

To lightweight member cluster installation, this pr help us to run ks-controller-manager without ldap option.

Which issue(s) this PR fixes:

Fixes #3056

Special notes for reviewers:

This pr is only for ldap. I will create another one for redis.

Additional documentation, usage docs, etc.:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment