Skip to content

Commit

Permalink
add docs and fix authorization
Browse files Browse the repository at this point in the history
  • Loading branch information
sjmshsh committed Sep 13, 2023
1 parent 2e5e496 commit 8db418b
Show file tree
Hide file tree
Showing 35 changed files with 1,148 additions and 25 deletions.
1 change: 1 addition & 0 deletions .licenserc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ header:
- '**/templates/**'
- '**/testdata/**'
- '**/deploy.tpl'
- '**/docs/**'
comment: on-failure

license-location-threshold: 130
19 changes: 11 additions & 8 deletions app/dubboctl/cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ type ErrInvalidTemplate error
func addCreate(baseCmd *cobra.Command, newClient ClientFactory) {
cmd := &cobra.Command{
Use: "create",
Short: "Create a application",
Short: "Create an application",
Long: `
NAME
{{.Name}} create - Create a function
{{.Name}} create - Create an application
SYNOPSIS
{{.Name}} create [-l|--language] [-t|--template] [-r|--repository]
[-c|--confirm] [path]
DESCRIPTION
Creates a new function project.
Creates a new application.
$ {{.Name}} create -l go
Expand All @@ -67,6 +67,9 @@ DESCRIPTION
To complete this command interactively, use --confirm (-c):
$ {{.Name}} create -c
Initialize the current project directly into a dubbo project without using a template
$ dubboctl create --init
Available Language Runtimes and Templates:
{{ .Options | indent 2 " " | indent 1 "\t" }}
Expand All @@ -78,11 +81,11 @@ EXAMPLES
handles http events (the default template).
$ {{.Name}} create -l java
o Create a java common in the directory 'myfunc'.
$ {{.Name}} create -l java myfunc
o Create a java common in the directory 'mydubbo'.
$ {{.Name}} create -l java mydubbo
o Create a Main common in ./myfunc.
$ {{.Name}} create -l go -t common myfunc
o Create a Main common in ./mydubbo.
$ {{.Name}} create -l go -t common mydubbo
`,
SuggestFor: []string{"vreate", "creaet", "craete", "new"},
PreRunE: bindEnv("language", "template", "repository", "confirm", "init"),
Expand All @@ -97,7 +100,7 @@ EXAMPLES
cmd.Flags().StringP("template", "t", "", "Application template. (see help text for list) ($DUBBO_TEMPLATE)")
cmd.Flags().StringP("repository", "r", "", "URI to a Git repository containing the specified template ($DUBBO_REPOSITORY)")
cmd.Flags().BoolP("init", "i", false,
"")
"Initialize the current project directly into a dubbo project without using a template")

addConfirmFlag(cmd, false)

Expand Down
11 changes: 1 addition & 10 deletions app/dubboctl/cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package cmd
import (
"io"
"os"
"path/filepath"
"strings"
"testing"

Expand All @@ -32,15 +31,7 @@ func fromTempDirectory(t *testing.T) string {
t.Helper()
ClearEnvs(t)

// We have to define KUBECONFIG, or the file at ~/.kube/config (if extant)
// will be used (disrupting tests by using the current user's environment).
// The test kubeconfig set below has the current namespace set to 'func'
// NOTE: the below settings affect unit tests only, and we do explicitly
// want all unit tests to start in an empty environment with tests "opting in"
// to config, not opting out.
t.Setenv("KUBECONFIG", filepath.Join(cwd(), "testdata", "default_kubeconfig"))

// By default unit tests presum no config exists unless provided in testdata.
// By default unit tests presume no config exists unless provided in testdata.
t.Setenv("XDG_CONFIG_HOME", t.TempDir())

// creates and CDs to a temp directory
Expand Down
2 changes: 1 addition & 1 deletion app/dubboctl/internal/dubbo/repositories_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestRepositories_Get(t *testing.T) {
}

// TestRepositories_All ensures repos are returned from
// .All accessor. Tests both builtin and buitlin+extensible cases.
// .All accessor. Tests both builtin and building+extensible cases.
func TestRepositories_All(t *testing.T) {
uri := ServeRepo(RepositoriesTestRepo, t)
root, rm := Mktemp(t)
Expand Down
4 changes: 2 additions & 2 deletions app/dubboctl/internal/testing/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,11 @@ func Cwd() (cwd string) {

// ClearEnvs sets all environment variables with the prefix of FUNC_ to
// empty (unsets) for the duration of the test t and is used when
// a test needs to completely clear dubbo-releated envs prior to running.
// a test needs to completely clear dubbo-related envs prior to running.
func ClearEnvs(t *testing.T) {
t.Helper()
for _, v := range os.Environ() {
if strings.HasPrefix(v, "FUNC_") {
if strings.HasPrefix(v, "DUBBO_") {
parts := strings.SplitN(v, "=", 2)
t.Setenv(parts[0], "")
}
Expand Down
186 changes: 186 additions & 0 deletions docs/cmd/dubboctl/Concepts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
# Concepts

## dubboctl Manifest and Profile

### Manifest

Dubbo-kubernetes, as a central control component, needs to launch various components such as Grafana, Prometheus,
Skywalking, Zipkin, Nacos, Zookeeper, etc., to provide additional functionality. In a Kubernetes environment, the
configuration YAML that describes these components is referred to as the "manifest." It's also the final result
processed by dubboctl, which can be used with tools like kubectl to directly launch the required components.

Dubboctl utilizes the Helm API to render the Helm Charts for various components to generate the manifest. Among these,
the Helm Charts for Admin and Nacos are maintained by the Dubbo-admin community, while other mature components use Helm
Charts provided by their official sources. (For more information on how Helm works, please refer
to https://helm.sh/zh/docs/)

### DubboConfig YAML (Profile)

DubboConfig YAML and Profile essentially have the same format and field meanings in YAML configuration files. However,
they serve different purposes and are kept separate. DubboConfig YAML is user-facing and represents custom requirements,
whereas profiles are refined and provided by Dubbo-admin (users can also set custom profiles) to represent basic
configurations for different scenarios. Currently, the community offers two types of profiles: "default" and "demo."

A typical DubboConfig YAML looks like this:

```yaml
# DubboConfig example
apiVersion: dubbo.apache.org/v1alpha1
kind: DubboConfig
metadata:
namespace: dubbo-system
spec:
# kubectl basic metadata

# Profile specifies the base default configuration to use. If using the profile provided by Dubbo-admin,
# you can currently specify either "default" or "demo."
profile: default
namespace: dubbo-system

# Metadata for configuring components. For components maintained by Dubbo-admin, you can configure "enabled,"
# while other mature components can have repository URLs and Helm Chart versions.
componentsMeta:
# Components maintained by Dubbo-admin
admin:
enabled: true
# Mature components
grafana:
enabled: true
repoURL: https://grafana.github.io/helm-charts
version: 6.52.4

# Configure each component, where the values in components.admin and components.grafana fields
# will be mapped directly to the values.yaml of the respective Helm Chart.
components:
admin:
replicas: 2
grafana:
testFramework:
enabled: true
```
The default profile is as follows:
```yaml
apiVersion: dubbo.apache.org/v1alpha1
kind: DubboOperator
metadata:
namespace: dubbo-system
spec:
profile: default
namespace: dubbo-system
# The default profile launches admin and zookeeper components by default
componentsMeta:
admin:
enabled: true
zookeeper:
enabled: true
repoURL: https://charts.bitnami.com/bitnami
version: 11.1.6
```
The demo profile is as follows:
```yaml
apiVersion: dubbo.apache.org/v1alpha1
kind: DubboOperator
metadata:
namespace: dubbo-system
spec:
profile: demo
namespace: dubbo-system
# The demo profile launches all components by default
componentsMeta:
admin:
enabled: true
grafana:
enabled: true
repoURL: https://grafana.github.io/helm-charts
version: 6.52.4
nacos:
enabled: true
zookeeper:
enabled: true
repoURL: https://charts.bitnami.com/bitnami
version: 11.1.6
prometheus:
enabled: true
repoURL: https://prometheus-community.github.io/helm-charts
version: 20.0.2
skywalking:
enabled: true
repoURL: https://apache.jfrog.io/artifactory/skywalking-helm
version: 4.3.0
zipkin:
enabled: true
repoURL: https://openzipkin.github.io/zipkin
version: 0.3.0
```
You can see that DubboConfig consists of three parts: dubboctl metadata, componentsMeta, and components. The dubboctl
metadata can specify the profile, componentsMeta controls the toggles for components, and mature components can have
repository addresses and Helm Chart versions specified. Here, let's focus on components. As mentioned in the manifest
section, dubboctl uses the Helm API to render Helm Charts, and the values.yaml required by each chart is derived from
the field values in the components section. For example, the values in components.admin will be directly mapped to the
values.yaml of the Dubbo-kubernetes
chart (https://github.com/apache/dubbo-kubernetes/blob/master/deploy/charts/dubbo-admin/values.yaml).
### Overlay
Profiles, as basic configuration items, can be applied over user-defined DubboConfig YAML using an Overlay mechanism.
For example, overlaying the DubboConfig YAML example from the previous section onto the default profile results in:
```yaml
# DubboConfig example
apiVersion: dubbo.apache.org/v1alpha1
kind: DubboConfig
metadata:
namespace: dubbo-system
spec:
# kubectl basic metadata

# Profile specifies the base default configuration to use. If using the profile provided by Dubbo-admin,
# you can currently specify either "default" or "demo."
profile: default
namespace: dubbo-system

# Metadata for configuring components. For components maintained by Dubbo-admin, you can configure "enabled,"
# while other mature components can have repository URLs and Helm Chart versions.
componentsMeta:
# Components maintained by Dubbo-admin
admin:
enabled: true
# Mature components
grafana:
enabled: true
repoURL: https://grafana.github.io/helm-charts
version: 6.52.4
zookeeper:
enabled: true
repoURL: https://charts.bitnami.com/bitnami
version: 11.1.6

# Configure each component, where the values in components.admin and components.grafana fields
# will be mapped directly to the values.yaml of the respective Helm Chart.
components:
admin:
replicas: 2
grafana:
testFramework:
enabled: true
```
Currently, Overlay is implemented using JSON Merge Patch (https://datatracker.ietf.org/doc/html/rfc7396).
## dubboctl Create
### .dubbo Directory
When you create an application using dubboctl in the correct manner, you'll notice that a ".dubbo" directory is
generated. The purpose of this hidden file is to determine whether the application needs to build an image. If the code
hasn't been changed, it won't build an image by default unless you include the "--force" flag.
## dubbo.yaml
dubbo.yaml is a metadata recording file that contains a portion of the data used by dubboctl when it runs. Some of your
actions will be recorded in dubbo.yaml, and it takes precedence when you use
Loading

0 comments on commit 8db418b

Please sign in to comment.