Skip to content

Latest commit

 

History

History
103 lines (66 loc) · 3.49 KB

DEVELOPMENT.md

File metadata and controls

103 lines (66 loc) · 3.49 KB

Developing

The main development of Horizon is concentrated on horizon-core and horizon-web. The fallowing method is proposed to facilitate your development and debugging:

Requirements

Horizon-core

Horizon-core is a web server built with gin framework. Due to its complex interaction with other components, nocalhost, a cloud-native development tool, could be used to improve your development and debugging.

Nocalhost can help you to connect directly to the Kubernetes cluster using KubeConfig with one click, and enjoy the coding in-cluster, which gets rid of the pesky local environment configurations. See: Nocalhost Introduction.

Install Nocalhost Extension

  1. Open the extension market of your favourite IDE.
  2. Input Nocalhost in the search box.
  3. Select the Nocalhost Extension, and click the Install button.

For example in goland:

nocalhost-extension

Connect to Kubernetes Cluster

  1. Click on the Nocalhost icon on the side panel, open the Nocalhost plugin.
  2. Click the + button to add your kubeconfig path or content, then select context and namespace.

nocalhost-add

  1. If successful, your kubernetes cluster will be ACTIVE shown in Nocalhost panel.

nocalhost-active

Note that just like kubectl, you can access any kubernetes cluster by nocalhost with a proper kubeconfig, no matter kind or cloud k8s.

Start DevMode

  1. Expand your cluster in nocalhost panel, and click horizoncd -> horizon ->Deployments.

  2. Right-click the workload horizon-core and click Start DevMode . nocalhost-workload

Remote Debug

  1. Click Remote Debug in the right-click menu, and wait for the project to start. nocalhost-remote-debug

  2. The following logs shown in IDE debug panel indicate that the project is running. core-running

    Now, you can add breakpoints in your code and debug them.

    core-debug

Horizon-web

Horizon-web only communicates with horizon-core, which is exposed by the ingress domain. Therefore, you can easily run and debug it using the following method:

Change Proxy

  1. Open horizon-web project in your IDE, then open config/proxy.ts file.
  2. Change proxy target to forward requests to horizon-core deployed in your kubernetes.
// config/proxy.ts
export default {
  dev: {
    '/apis/': {
      // target: 'http://localhost:8080',
      target: 'http://horizon.localtest.me',
      changeOrigin: true,
      pathRewrite: { '^': '' },
    },
  },
};

Debug

  1. Prepare all dependencies of the project and then start it using the yarn command line tool.
# prepare
yarn
# start
yarn start

You can see all scripts of yarn in fille package.json, which is useful during your development.

  1. When the project is running, visit http://localhost:8000 to check your local web service for debugging.

    web-running

    web-debug