Skip to content

Commit

Permalink
update swagger info for SwaggerUI (#1009)
Browse files Browse the repository at this point in the history
* fix: config argoCD and fluxCD by kubesphere.yaml

* filter out ApiVersions that not start with /kapis

* update swagger info
  • Loading branch information
yudong2015 authored Oct 24, 2023
1 parent 6834bd0 commit 41bb584
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 12 deletions.
4 changes: 2 additions & 2 deletions cmd/apiserver/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ func (s *ServerRunOptions) Flags() (fss cliflag.NamedFlagSets) {
s.JenkinsOptions.AddFlags(fss.FlagSet("devops"), s.JenkinsOptions)
s.SonarQubeOptions.AddFlags(fss.FlagSet("sonarqube"), s.SonarQubeOptions)
s.S3Options.AddFlags(fss.FlagSet("s3"), s.S3Options)
s.ArgoCDOption.AddFlags(fss.FlagSet("argocd"))
s.FluxCDOption.AddFlags(fss.FlagSet("fluxcd"))
s.ArgoCDOption.AddFlags(fss.FlagSet("argocd"), s.ArgoCDOption)
s.FluxCDOption.AddFlags(fss.FlagSet("fluxcd"), s.FluxCDOption)

fs = fss.FlagSet("klog")
local := flag.NewFlagSet("klog", flag.ExitOnError)
Expand Down
2 changes: 1 addition & 1 deletion cmd/controller/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (s *DevOpsControllerManagerOptions) Flags() cliflag.NamedFlagSets {
s.KubernetesOptions.AddFlags(fss.FlagSet("kubernetes"), s.KubernetesOptions)
s.JenkinsOptions.AddFlags(fss.FlagSet("devops"), s.JenkinsOptions)
s.FeatureOptions.AddFlags(fss.FlagSet("feature"), s.FeatureOptions)
s.ArgoCDOption.AddFlags(fss.FlagSet("argocd"))
s.ArgoCDOption.AddFlags(fss.FlagSet("argocd"), s.ArgoCDOption)

fs := fss.FlagSet("leaderelection")
s.bindLeaderElectionFlags(s.LeaderElection, fs)
Expand Down
5 changes: 4 additions & 1 deletion docs/swagger.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ make swagger-ui
Then, start the APIServer and explore all API documentation via the Swagger UI: <http://localhost:9090/apidocs/?url=http://localhost:9090/apidocs.json>.


* The URL pattern is like `http://ip:port/apidocs/?url=http://ip:port/apidocs.json`
* The URL pattern is like `http://ip:port/apidocs/?url=http://ip:port/apidocs.json`

---
In kubesphere enabled DevOps, you could update service type of devops-apiserver to NodePort, and then via the Swagger UI: `http://ip:NodePort/apidocs/?url=http://ip:NodePort/apidocs.json`.
12 changes: 6 additions & 6 deletions pkg/config/gitops.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ import (

// ArgoCDOption as the ArgoCD integration configuration
type ArgoCDOption struct {
Enabled bool `json:"enabled,omitempty" yaml:"enabled,omitempty" description:"enabled FluxCD"`
Enabled bool `json:"enabled,omitempty" yaml:"enabled,omitempty" description:"enabled ArgoCD"`
Namespace string `json:"namespace,omitempty" yaml:"namespace,omitempty" description:"Which namespace the ArgoCD located"`
}

// AddFlags adds the flags which related to argocd
func (o *ArgoCDOption) AddFlags(fs *pflag.FlagSet) {
fs.BoolVar(&o.Enabled, "argocd-enabled", false, "Enable ArgoCD APIs")
func (o *ArgoCDOption) AddFlags(fs *pflag.FlagSet, parentOptions *ArgoCDOption) {
fs.BoolVar(&o.Enabled, "argocd-enabled", parentOptions.Enabled, "Enable ArgoCD APIs")
// see also https://argo-cd.readthedocs.io/en/stable/getting_started/
fs.StringVarP(&o.Namespace, "argocd-namespace", o.Namespace, "argocd", "Which namespace the ArgoCD located")
fs.StringVar(&o.Namespace, "argocd-namespace", parentOptions.Namespace, "Which namespace the ArgoCD located")
}

// FluxCDOption as the FluxCD integration configuration
Expand All @@ -40,8 +40,8 @@ type FluxCDOption struct {
}

// AddFlags adds the flags which related to fluxcd
func (o *FluxCDOption) AddFlags(fs *pflag.FlagSet) {
fs.BoolVar(&o.Enabled, "fluxcd-enabled", false, "Enable FluxCD APIs")
func (o *FluxCDOption) AddFlags(fs *pflag.FlagSet, parentOptions *FluxCDOption) {
fs.BoolVar(&o.Enabled, "fluxcd-enabled", parentOptions.Enabled, "Enable FluxCD APIs")
}

// GetGitOpsEngine return gitops engine type
Expand Down
22 changes: 20 additions & 2 deletions pkg/kapis/doc/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,32 @@ package doc
import (
"github.com/emicklei/go-restful"
swagger "github.com/emicklei/go-restful-swagger12"
"kubesphere.io/devops/pkg/apiserver/runtime"
"strings"
)

// AddSwaggerService adds the Swagger service
func AddSwaggerService(wss []*restful.WebService, c *restful.Container) {
var wssWithSchema []*restful.WebService
for _, service := range wss {
if strings.HasPrefix(service.RootPath(), runtime.ApiRootPath) {
wssWithSchema = append(wssWithSchema, service)
}
}

config := swagger.Config{
WebServices: wss,
WebServices: wssWithSchema,
ApiPath: "/apidocs.json",
SwaggerPath: "/apidocs/",
SwaggerFilePath: "bin/swagger-ui/dist"}
SwaggerFilePath: "bin/swagger-ui/dist",
Info: swagger.Info{
Title: "KubeSphere DevOps",
Description: "KubeSphere DevOps OpenAPI",
TermsOfServiceUrl: "https://kubesphere.io/",
Contact: "kubesphere@yunify.com",
License: "Apache 2.0",
LicenseUrl: "https://www.apache.org/licenses/LICENSE-2.0.html",
},
}
swagger.RegisterSwaggerService(config, c)
}

0 comments on commit 41bb584

Please sign in to comment.