Unify the omitempty configuration of YAML annotation

This commit is contained in:
Xinzhao Xu
2022-02-21 16:25:55 +08:00
parent f50de9af65
commit c53001c5dc
20 changed files with 68 additions and 70 deletions

View File

@@ -63,10 +63,10 @@ type Options struct {
Issuer string `json:"issuer,omitempty" yaml:"issuer,omitempty"`
// RSA private key file used to sign the id token
SignKey string `json:"signKey,omitempty" yaml:"signKey"`
SignKey string `json:"signKey,omitempty" yaml:"signKey,omitempty"`
// Raw RSA private key. Base64 encoded PEM file
SignKeyData string `json:"-,omitempty" yaml:"signKeyData"`
SignKeyData string `json:"-,omitempty" yaml:"signKeyData,omitempty"`
// Register identity providers.
IdentityProviders []IdentityProviderOptions `json:"identityProviders,omitempty" yaml:"identityProviders,omitempty"`
@@ -191,7 +191,7 @@ type Token struct {
type Client struct {
// The name of the OAuth client is used as the client_id parameter when making requests to <master>/oauth/authorize
// and <master>/oauth/token.
Name string `json:"name" yaml:"name,omitempty"`
Name string `json:"name,omitempty" yaml:"name,omitempty"`
// Secret is the unique secret associated with a client
Secret string `json:"-" yaml:"secret,omitempty"`

View File

@@ -28,7 +28,7 @@ import (
)
type Options struct {
Mode string `json:"mode" yaml:"mode"`
Mode string `json:"mode" yaml:"mode"`
}
func NewOptions() *Options {

View File

@@ -19,26 +19,24 @@ package config
import (
"fmt"
"io/ioutil"
"os"
"testing"
"time"
"kubesphere.io/kubesphere/pkg/apiserver/authentication"
"kubesphere.io/kubesphere/pkg/apiserver/authorization"
"github.com/google/go-cmp/cmp"
"gopkg.in/yaml.v2"
networkv1alpha1 "kubesphere.io/api/network/v1alpha1"
"kubesphere.io/kubesphere/pkg/apiserver/authentication"
"kubesphere.io/kubesphere/pkg/apiserver/authentication/oauth"
"kubesphere.io/kubesphere/pkg/apiserver/authorization"
"kubesphere.io/kubesphere/pkg/models/terminal"
"kubesphere.io/kubesphere/pkg/simple/client/alerting"
"kubesphere.io/kubesphere/pkg/simple/client/auditing"
"kubesphere.io/kubesphere/pkg/simple/client/cache"
"kubesphere.io/kubesphere/pkg/simple/client/devops/jenkins"
edgeruntime "kubesphere.io/kubesphere/pkg/simple/client/edgeruntime"
"kubesphere.io/kubesphere/pkg/simple/client/edgeruntime"
"kubesphere.io/kubesphere/pkg/simple/client/events"
"kubesphere.io/kubesphere/pkg/simple/client/gateway"
"kubesphere.io/kubesphere/pkg/simple/client/gpu"
@@ -58,7 +56,6 @@ import (
)
func newTestConfig() (*Config, error) {
var conf = &Config{
DevopsOptions: &jenkins.Options{
Host: "http://ks-devops.kubesphere-devops-system.svc",
@@ -87,6 +84,9 @@ func newTestConfig() (*Config, error) {
ManagerPassword: "P@88w0rd",
UserSearchBase: "ou=Users,dc=example,dc=org",
GroupSearchBase: "ou=Groups,dc=example,dc=org",
InitialCap: 10,
MaxCap: 100,
PoolName: "ldap",
},
RedisOptions: &cache.Options{
Host: "localhost",
@@ -96,7 +96,7 @@ func newTestConfig() (*Config, error) {
},
S3Options: &s3.Options{
Endpoint: "http://minio.openpitrix-system.svc",
Region: "",
Region: "us-east-1",
DisableSSL: false,
ForcePathStyle: false,
AccessKeyID: "ABCDEFGHIJKLMN",
@@ -167,9 +167,7 @@ func newTestConfig() (*Config, error) {
AccessTokenInactivityTimeout: 0,
},
},
MultiClusterOptions: &multicluster.Options{
Enable: false,
},
MultiClusterOptions: multicluster.NewOptions(),
EventsOptions: &events.Options{
Host: "http://elasticsearch-logging-data.kubesphere-logging-system.svc:9200",
IndexPrefix: "ks-logstash-events",

View File

@@ -3,8 +3,8 @@ package terminal
import "github.com/spf13/pflag"
type Options struct {
Image string `json:"image,omitempty" yaml:"image"`
Timeout int `json:"timeout,omitempty" yaml:"timeout"`
Image string `json:"image,omitempty" yaml:"image,omitempty"`
Timeout int `json:"timeout,omitempty" yaml:"timeout,omitempty"`
}
func NewTerminalOptions() *Options {

View File

@@ -37,7 +37,7 @@ type Options struct {
BasicAuth bool `json:"basicAuth" yaml:"basicAuth"`
Username string `json:"username" yaml:"username"`
Password string `json:"password" yaml:"password"`
IndexPrefix string `json:"indexPrefix,omitempty" yaml:"indexPrefix"`
IndexPrefix string `json:"indexPrefix,omitempty" yaml:"indexPrefix,omitempty"`
Version string `json:"version" yaml:"version"`
}

View File

@@ -23,10 +23,10 @@ import (
)
type Options struct {
Host string `json:"host"`
Port int `json:"port"`
Password string `json:"password"`
DB int `json:"db"`
Host string `json:"host" yaml:"host"`
Port int `json:"port" yaml:"port"`
Password string `json:"password" yaml:"password"`
DB int `json:"db" yaml:"db"`
}
// NewRedisOptions returns options points to nowhere,

View File

@@ -25,11 +25,11 @@ import (
)
type Options struct {
Host string `json:",omitempty" yaml:"host" description:"Jenkins service host address"`
Username string `json:",omitempty" yaml:"username" description:"Jenkins admin username"`
Password string `json:",omitempty" yaml:"password" description:"Jenkins admin password"`
MaxConnections int `json:"maxConnections,omitempty" yaml:"maxConnections" description:"Maximum connections allowed to connect to Jenkins"`
Endpoint string `json:"endpoint,omitempty" yaml:"endpoint" description:"The endpoint of the ks-devops apiserver"`
Host string `json:",omitempty" yaml:"host,omitempty" description:"Jenkins service host address"`
Username string `json:",omitempty" yaml:"username,omitempty" description:"Jenkins admin username"`
Password string `json:",omitempty" yaml:"password,omitempty" description:"Jenkins admin password"`
MaxConnections int `json:"maxConnections,omitempty" yaml:"maxConnections,omitempty" description:"Maximum connections allowed to connect to Jenkins"`
Endpoint string `json:"endpoint,omitempty" yaml:"endpoint,omitempty" description:"The endpoint of the ks-devops apiserver"`
}
// NewDevopsOptions returns a `zero` instance

View File

@@ -27,7 +27,7 @@ type Options struct {
BasicAuth bool `json:"basicAuth" yaml:"basicAuth"`
Username string `json:"username" yaml:"username"`
Password string `json:"password" yaml:"password"`
IndexPrefix string `json:"indexPrefix,omitempty" yaml:"indexPrefix"`
IndexPrefix string `json:"indexPrefix,omitempty" yaml:"indexPrefix,omitempty"`
Version string `json:"version" yaml:"version"`
}

View File

@@ -24,17 +24,17 @@ import (
// Options contains configuration of the default Gateway
type Options struct {
WatchesPath string `json:"watchesPath,omitempty" yaml:"watchesPath"`
Namespace string `json:"namespace,omitempty" yaml:"namespace"`
Repository string `json:"repository,omitempty" yaml:"repository"`
Tag string `json:"tag,omitempty" yaml:"tag"`
WatchesPath string `json:"watchesPath,omitempty" yaml:"watchesPath,omitempty"`
Namespace string `json:"namespace,omitempty" yaml:"namespace,omitempty"`
Repository string `json:"repository,omitempty" yaml:"repository,omitempty"`
Tag string `json:"tag,omitempty" yaml:"tag,omitempty"`
}
// NewGatewayOptions creates a default Gateway Option
func NewGatewayOptions() *Options {
return &Options{
WatchesPath: "",
Namespace: "", //constants.KubeSphereControlNamespace
Namespace: "", // constants.KubeSphereControlNamespace
Repository: "",
Tag: "",
}

View File

@@ -3,13 +3,13 @@ package gpu
import "github.com/spf13/pflag"
type GPUKind struct {
ResourceName string `json:"resourceName,omitempty" yaml:"resourceName"`
ResourceType string `json:"resourceType,omitempty" yaml:"resourceType"`
Default bool `json:"default,omitempty" yaml:"default"`
ResourceName string `json:"resourceName,omitempty" yaml:"resourceName,omitempty"`
ResourceType string `json:"resourceType,omitempty" yaml:"resourceType,omitempty"`
Default bool `json:"default,omitempty" yaml:"default,omitempty"`
}
type Options struct {
Kinds []GPUKind `json:"kinds,omitempty" yaml:"kinds"`
Kinds []GPUKind `json:"kinds,omitempty" yaml:"kinds,omitempty"`
}
func NewGPUOptions() *Options {

View File

@@ -36,15 +36,15 @@ type KubernetesOptions struct {
// kubernetes apiserver public address, used to generate kubeconfig
// for downloading, default to host defined in kubeconfig
// +optional
Master string `json:"master,omitempty" yaml:"master"`
Master string `json:"master,omitempty" yaml:"master,omitempty"`
// kubernetes clientset qps
// +optional
QPS float32 `json:"qps,omitempty" yaml:"qps"`
QPS float32 `json:"qps,omitempty" yaml:"qps,omitempty"`
// kubernetes clientset burst
// +optional
Burst int `json:"burst,omitempty" yaml:"burst"`
Burst int `json:"burst,omitempty" yaml:"burst,omitempty"`
}
// NewKubernetesOptions returns a `zero` instance

View File

@@ -23,14 +23,14 @@ import (
)
type Options struct {
Host string `json:"host,omitempty" yaml:"host"`
ManagerDN string `json:"managerDN,omitempty" yaml:"managerDN"`
ManagerPassword string `json:"managerPassword,omitempty" yaml:"managerPassword"`
UserSearchBase string `json:"userSearchBase,omitempty" yaml:"userSearchBase"`
GroupSearchBase string `json:"groupSearchBase,omitempty" yaml:"groupSearchBase"`
InitialCap int `json:"initialCap,omitempty" yaml:"initialCap"`
MaxCap int `json:"maxCap,omitempty" yaml:"maxCap"`
PoolName string `json:"poolName,omitempty" yaml:"poolName"`
Host string `json:"host,omitempty" yaml:"host,omitempty"`
ManagerDN string `json:"managerDN,omitempty" yaml:"managerDN,omitempty"`
ManagerPassword string `json:"managerPassword,omitempty" yaml:"managerPassword,omitempty"`
UserSearchBase string `json:"userSearchBase,omitempty" yaml:"userSearchBase,omitempty"`
GroupSearchBase string `json:"groupSearchBase,omitempty" yaml:"groupSearchBase,omitempty"`
InitialCap int `json:"initialCap,omitempty" yaml:"initialCap,omitempty"`
MaxCap int `json:"maxCap,omitempty" yaml:"maxCap,omitempty"`
PoolName string `json:"poolName,omitempty" yaml:"poolName,omitempty"`
}
// NewOptions return a default option

View File

@@ -27,7 +27,7 @@ type Options struct {
BasicAuth bool `json:"basicAuth" yaml:"basicAuth"`
Username string `json:"username" yaml:"username"`
Password string `json:"password" yaml:"password"`
IndexPrefix string `json:"indexPrefix,omitempty" yaml:"indexPrefix"`
IndexPrefix string `json:"indexPrefix,omitempty" yaml:"indexPrefix,omitempty"`
Version string `json:"version" yaml:"version"`
}

View File

@@ -21,7 +21,7 @@ import (
)
type Options struct {
Endpoint string `json:"endpoint,omitempty" yaml:"endpoint"`
Endpoint string `json:"endpoint,omitempty" yaml:"endpoint,omitempty"`
}
func NewPrometheusOptions() *Options {

View File

@@ -31,28 +31,28 @@ const (
type Options struct {
// Enable
Enable bool `json:"enable"`
EnableFederation bool `json:"enableFederation,omitempty"`
Enable bool `json:"enable" yaml:"enable"`
EnableFederation bool `json:"enableFederation,omitempty" yaml:"enableFederation,omitempty"`
// ProxyPublishService is the service name of multicluster component tower.
// If this field provided, apiserver going to use the ingress.ip of this service.
// This field will be used when generating agent deployment yaml for joining clusters.
ProxyPublishService string `json:"proxyPublishService,omitempty"`
ProxyPublishService string `json:"proxyPublishService,omitempty" yaml:"proxyPublishService,omitempty"`
// ProxyPublishAddress is the public address of tower for all cluster agents.
// This field takes precedence over field ProxyPublishService.
// If both field ProxyPublishService and ProxyPublishAddress are empty, apiserver will
// return 404 Not Found for all cluster agent yaml requests.
ProxyPublishAddress string `json:"proxyPublishAddress,omitempty"`
ProxyPublishAddress string `json:"proxyPublishAddress,omitempty" yaml:"proxyPublishAddress,omitempty"`
// AgentImage is the image used when generating deployment for all cluster agents.
AgentImage string `json:"agentImage,omitempty"`
AgentImage string `json:"agentImage,omitempty" yaml:"agentImage,omitempty"`
// ClusterControllerResyncPeriod is the resync period used by cluster controller.
ClusterControllerResyncPeriod time.Duration `json:"clusterControllerResyncPeriod,omitempty" yaml:"clusterControllerResyncPeriod"`
ClusterControllerResyncPeriod time.Duration `json:"clusterControllerResyncPeriod,omitempty" yaml:"clusterControllerResyncPeriod,omitempty"`
// HostClusterName is the name of the control plane cluster, default set to host.
HostClusterName string `json:"hostClusterName,omitempty" yaml:"hostClusterName"`
HostClusterName string `json:"hostClusterName,omitempty" yaml:"hostClusterName,omitempty"`
}
// NewOptions returns a default nil options

View File

@@ -27,7 +27,7 @@ type NSNPOptions struct {
}
type Options struct {
EnableNetworkPolicy bool `json:"enableNetworkPolicy,omitempty" yaml:"enableNetworkPolicy"`
EnableNetworkPolicy bool `json:"enableNetworkPolicy,omitempty" yaml:"enableNetworkPolicy,omitempty"`
NSNPOptions NSNPOptions `json:"nsnpOptions,omitempty" yaml:"nsnpOptions,omitempty"`
WeaveScopeHost string `json:"weaveScopeHost,omitempty" yaml:"weaveScopeHost,omitempty"`
IPPoolType string `json:"ippoolType,omitempty" yaml:"ippoolType,omitempty"`

View File

@@ -17,7 +17,7 @@ limitations under the License.
package notification
type Options struct {
Endpoint string
Endpoint string `json:"endpoint,omitempty" yaml:"endpoint,omitempty"`
}
func NewNotificationOptions() *Options {

View File

@@ -24,14 +24,14 @@ import (
// Options contains configuration to access a s3 service
type Options struct {
Endpoint string `json:"endpoint,omitempty" yaml:"endpoint"`
Region string `json:"region,omitempty" yaml:"region"`
Endpoint string `json:"endpoint,omitempty" yaml:"endpoint,omitempty"`
Region string `json:"region,omitempty" yaml:"region,omitempty"`
DisableSSL bool `json:"disableSSL" yaml:"disableSSL"`
ForcePathStyle bool `json:"forcePathStyle" yaml:"forcePathStyle"`
AccessKeyID string `json:"accessKeyID,omitempty" yaml:"accessKeyID"`
SecretAccessKey string `json:"secretAccessKey,omitempty" yaml:"secretAccessKey"`
SessionToken string `json:"sessionToken,omitempty" yaml:"sessionToken"`
Bucket string `json:"bucket,omitempty" yaml:"bucket"`
AccessKeyID string `json:"accessKeyID,omitempty" yaml:"accessKeyID,omitempty"`
SecretAccessKey string `json:"secretAccessKey,omitempty" yaml:"secretAccessKey,omitempty"`
SessionToken string `json:"sessionToken,omitempty" yaml:"sessionToken,omitempty"`
Bucket string `json:"bucket,omitempty" yaml:"bucket,omitempty"`
}
// NewS3Options creates a default disabled Options(empty endpoint)

View File

@@ -21,16 +21,16 @@ import "github.com/spf13/pflag"
type Options struct {
// istio pilot discovery service url
IstioPilotHost string `json:"istioPilotHost,omitempty" yaml:"istioPilotHost"`
IstioPilotHost string `json:"istioPilotHost,omitempty" yaml:"istioPilotHost,omitempty"`
// jaeger query service url
JaegerQueryHost string `json:"jaegerQueryHost,omitempty" yaml:"jaegerQueryHost"`
JaegerQueryHost string `json:"jaegerQueryHost,omitempty" yaml:"jaegerQueryHost,omitempty"`
// kiali query service url
KialiQueryHost string `json:"kialiQueryHost,omitempty" yaml:"kialiQueryHost"`
KialiQueryHost string `json:"kialiQueryHost,omitempty" yaml:"kialiQueryHost,omitempty"`
// prometheus service url for servicemesh metrics
ServicemeshPrometheusHost string `json:"servicemeshPrometheusHost,omitempty" yaml:"servicemeshPrometheusHost"`
ServicemeshPrometheusHost string `json:"servicemeshPrometheusHost,omitempty" yaml:"servicemeshPrometheusHost,omitempty"`
}
// NewServiceMeshOptions returns a `zero` instance

View File

@@ -21,8 +21,8 @@ import (
)
type Options struct {
Host string `json:",omitempty" yaml:"host" description:"SonarQube service host address"`
Token string `json:",omitempty" yaml:"token" description:"SonarQube service token"`
Host string `json:",omitempty" yaml:"host,omitempty" description:"SonarQube service host address"`
Token string `json:",omitempty" yaml:"token,omitempty" description:"SonarQube service token"`
}
func NewSonarQubeOptions() *Options {