Skip to content

Commit

Permalink
feat(application): support dryrun
Browse files Browse the repository at this point in the history
  • Loading branch information
jianzhuang authored and tke-robot committed Sep 25, 2020
1 parent c45ef42 commit 883d4c4
Show file tree
Hide file tree
Showing 25 changed files with 471 additions and 142 deletions.
8 changes: 6 additions & 2 deletions api/application/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ type AppSpec struct {
Chart Chart
// Values holds the values for this app.
// +optional
Values AppValues
// +optional
Values AppValues
Finalizers []FinalizerName
// +optional
DryRun bool
}

// Chart is a description of a chart.
Expand Down Expand Up @@ -110,6 +111,9 @@ type AppStatus struct {
// A human readable message indicating details about the transition.
// +optional
Message string
// Dryrun result.
// +optional
Manifest string
}

// +genclient
Expand Down
245 changes: 159 additions & 86 deletions api/application/v1/generated.pb.go

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions api/application/v1/generated.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions api/application/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type AppSpec struct {
Values AppValues `json:"values,omitempty" protobuf:"bytes,6,opt,name=values,casttype=AppValues"`
// +optional
Finalizers []FinalizerName `json:"finalizers,omitempty" protobuf:"bytes,7,rep,name=finalizers,casttype=FinalizerName"`
DryRun bool `json:"dryRun" protobuf:"bytes,8,opt,name=dryRun"`
}

// Chart is a description of a chart.
Expand Down Expand Up @@ -110,6 +111,9 @@ type AppStatus struct {
// A human readable message indicating details about the transition.
// +optional
Message string `json:"message,omitempty" protobuf:"bytes,9,opt,name=message"`
// Dryrun result.
// +optional
Manifest string `json:"manifest" protobuf:"bytes,10,opt,name=manifest"`
}

// +genclient
Expand Down
1 change: 1 addition & 0 deletions api/application/v1/types_swagger_doc_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions api/application/v1/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion api/openapi/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions cmd/tke-application-api/app/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
"tkestack.io/tke/pkg/apiserver/openapi"
"tkestack.io/tke/pkg/apiserver/storage"
"tkestack.io/tke/pkg/application/apiserver"
appconfig "tkestack.io/tke/pkg/application/config"
controllerconfig "tkestack.io/tke/pkg/controller/config"
)

Expand All @@ -57,6 +58,7 @@ type Config struct {
StorageFactory *serverstorage.DefaultStorageFactory
RegistryClient registryversionedclient.RegistryV1Interface
PlatformClient platformversionedclient.PlatformV1Interface
RepoConfiguration appconfig.RepoConfiguration
}

// CreateConfigFromOptions creates a running configuration instance based
Expand Down Expand Up @@ -150,5 +152,9 @@ func CreateConfigFromOptions(serverName string, opts *options.Options) (*Config,
RegistryClient: registryClient.RegistryV1(),
}

if err := (&opts.FeatureOptions.Repo).ApplyTo(&cfg.RepoConfiguration); err != nil {
return nil, err
}

return cfg, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,26 @@ import (

"github.com/spf13/pflag"
"github.com/spf13/viper"
appconfig "tkestack.io/tke/pkg/application/controller/app/config"
appconfig "tkestack.io/tke/pkg/application/config"
)

const (
flagRepoScheme = "repo-scheme"
flagRepoDomainSuffix = "repo-domain-suffix"
flagRepoCaFile = "repo-cafile"
flagRepoAdmin = "repo-admin"
flagRepoAdminPassword = "repo-admin-password"
flagRepoScheme = "features-repo-scheme"
flagRepoDomainSuffix = "features-repo-domain-suffix"
flagRepoCaFile = "features-repo-cafile"
flagRepoAdmin = "features-repo-admin"
flagRepoAdminPassword = "features-repo-admin-password"
)

const (
configRepoScheme = "repo.scheme"
configRepoDomainSuffix = "repo.domain_suffix"
configRepoCaFile = "repo.cafile"
configRepoAdmin = "repo.admin"
configRepoAdminPassword = "repo.admin_password"
configRepoScheme = "features.repo.scheme"
configRepoDomainSuffix = "features.repo.domain_suffix"
configRepoCaFile = "features.repo.cafile"
configRepoAdmin = "features.repo.admin"
configRepoAdminPassword = "features.repo.admin_password"
)

// RepoOptions contains configuration items related to auth attributes.
// RepoOptions contains configuration items related to application attributes.
type RepoOptions struct {
Scheme string
DomainSuffix string
Expand All @@ -51,52 +51,57 @@ type RepoOptions struct {
AdminPassword string
}

// NewRepoOptions creates a RepoOptions object with default parameters.
func NewRepoOptions() *RepoOptions {
return &RepoOptions{}
// FeatureOptions contains configuration items related to application attributes.
type FeatureOptions struct {
Repo RepoOptions
}

// NewFeatureOptions creates a FeatureOptions object with default parameters.
func NewFeatureOptions() *FeatureOptions {
return &FeatureOptions{}
}

// AddFlags adds flags for console to the specified FlagSet object.
func (o *RepoOptions) AddFlags(fs *pflag.FlagSet) {
fs.String(flagRepoScheme, o.Scheme,
func (o *FeatureOptions) AddFlags(fs *pflag.FlagSet) {
fs.String(flagRepoScheme, o.Repo.Scheme,
"Chart repo server scheme.")
_ = viper.BindPFlag(configRepoScheme, fs.Lookup(flagRepoScheme))

fs.String(flagRepoDomainSuffix, o.DomainSuffix,
fs.String(flagRepoDomainSuffix, o.Repo.DomainSuffix,
"Chart repo domain suffix.")
_ = viper.BindPFlag(configRepoDomainSuffix, fs.Lookup(flagRepoDomainSuffix))

fs.String(flagRepoCaFile, o.CaFile,
fs.String(flagRepoCaFile, o.Repo.CaFile,
"CA certificate to verify peer against.")
_ = viper.BindPFlag(configRepoCaFile, fs.Lookup(flagRepoCaFile))

fs.String(flagRepoAdmin, o.Admin,
fs.String(flagRepoAdmin, o.Repo.Admin,
"Repo admin user.")
_ = viper.BindPFlag(configRepoAdmin, fs.Lookup(flagRepoAdmin))

fs.String(flagRepoAdminPassword, o.AdminPassword,
fs.String(flagRepoAdminPassword, o.Repo.AdminPassword,
"Repo admin user password.")
_ = viper.BindPFlag(configRepoAdminPassword, fs.Lookup(flagRepoAdminPassword))
}

// ApplyFlags parsing parameters from the command line or configuration file
// to the options instance.
func (o *RepoOptions) ApplyFlags() []error {
func (o *FeatureOptions) ApplyFlags() []error {
var errs []error

o.Scheme = viper.GetString(configRepoScheme)
if o.Scheme == "" {
o.Repo.Scheme = viper.GetString(configRepoScheme)
if o.Repo.Scheme == "" {
errs = append(errs, fmt.Errorf("--%s must be specified", flagRepoScheme))
}

o.DomainSuffix = viper.GetString(configRepoDomainSuffix)
if o.DomainSuffix == "" {
o.Repo.DomainSuffix = viper.GetString(configRepoDomainSuffix)
if o.Repo.DomainSuffix == "" {
errs = append(errs, fmt.Errorf("--%s must be specified", flagRepoDomainSuffix))
}

o.CaFile = viper.GetString(configRepoCaFile)
o.Admin = viper.GetString(configRepoAdmin)
o.AdminPassword = viper.GetString(configRepoAdminPassword)
o.Repo.CaFile = viper.GetString(configRepoCaFile)
o.Repo.Admin = viper.GetString(configRepoAdmin)
o.Repo.AdminPassword = viper.GetString(configRepoAdminPassword)

return errs
}
Expand Down
4 changes: 4 additions & 0 deletions cmd/tke-application-api/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type Options struct {
RegistryAPIClient *controlleroptions.APIServerClientOptions
PlatformAPIClient *controlleroptions.APIServerClientOptions
Audit *genericapiserveroptions.AuditOptions
FeatureOptions *FeatureOptions
}

// NewOptions creates a new Options with a default config.
Expand All @@ -57,6 +58,7 @@ func NewOptions(serverName string) *Options {
RegistryAPIClient: controlleroptions.NewAPIServerClientOptions("registry", true),
PlatformAPIClient: controlleroptions.NewAPIServerClientOptions("platform", true),
Audit: genericapiserveroptions.NewAuditOptions(),
FeatureOptions: NewFeatureOptions(),
}
}

Expand All @@ -72,6 +74,7 @@ func (o *Options) AddFlags(fs *pflag.FlagSet) {
o.RegistryAPIClient.AddFlags(fs)
o.PlatformAPIClient.AddFlags(fs)
o.Audit.AddFlags(fs)
o.FeatureOptions.AddFlags(fs)
}

// ApplyFlags parsing parameters from the command line or configuration file
Expand All @@ -88,6 +91,7 @@ func (o *Options) ApplyFlags() []error {
errs = append(errs, o.Authorization.ApplyFlags()...)
errs = append(errs, o.RegistryAPIClient.ApplyFlags()...)
errs = append(errs, o.PlatformAPIClient.ApplyFlags()...)
errs = append(errs, o.FeatureOptions.ApplyFlags()...)

return errs
}
Expand Down
1 change: 1 addition & 0 deletions cmd/tke-application-api/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func createAPIServerConfig(cfg *config.Config) *apiserver.Config {
APIResourceConfigSource: cfg.StorageFactory.APIResourceConfigSource,
RegistryClient: cfg.RegistryClient,
PlatformClient: cfg.PlatformClient,
RepoConfiguration: cfg.RepoConfiguration,
},
}
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/tke-application-controller/app/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
restclient "k8s.io/client-go/rest"
versionedclientset "tkestack.io/tke/api/client/clientset/versioned"
"tkestack.io/tke/cmd/tke-application-controller/app/options"
appconfig "tkestack.io/tke/pkg/application/controller/app/config"
appconfig "tkestack.io/tke/pkg/application/config"
controllerconfig "tkestack.io/tke/pkg/controller/config"
controlleroptions "tkestack.io/tke/pkg/controller/options"
)
Expand All @@ -49,7 +49,7 @@ type Config struct {
ApplicationAPIServerClientConfig *restclient.Config
// the rest config for the platform apiserver
PlatformAPIServerClientConfig *restclient.Config
Repo appconfig.RepoConfiguration
RepoConfiguration appconfig.RepoConfiguration
}

// CreateConfigFromOptions creates a running configuration instance based
Expand Down Expand Up @@ -93,7 +93,7 @@ func CreateConfigFromOptions(serverName string, opts *options.Options) (*Config,
PlatformAPIServerClientConfig: platformAPIServerClientConfig,
}

if err := opts.Repo.ApplyTo(&controllerManagerConfig.Repo); err != nil {
if err := (&opts.FeatureOptions.Repo).ApplyTo(&controllerManagerConfig.RepoConfiguration); err != nil {
return nil, err
}
if err := opts.Component.ApplyTo(&controllerManagerConfig.Component); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/tke-application-controller/app/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
platformv1 "tkestack.io/tke/api/client/clientset/versioned/typed/platform/v1"
versionedinformers "tkestack.io/tke/api/client/informers/externalversions"
"tkestack.io/tke/cmd/tke-application-controller/app/config"
appconfig "tkestack.io/tke/pkg/application/controller/app/config"
appconfig "tkestack.io/tke/pkg/application/config"
"tkestack.io/tke/pkg/controller"
"tkestack.io/tke/pkg/controller/util"
)
Expand Down Expand Up @@ -121,7 +121,7 @@ func CreateControllerContext(cfg *config.Config, rootClientBuilder controller.Cl
ResyncPeriod: controller.ResyncPeriod(&cfg.Component),
ControllerStartInterval: cfg.Component.ControllerStartInterval,

Repo: cfg.Repo,
Repo: cfg.RepoConfiguration,
PlatformClient: platformClient.PlatformV1(),
}

Expand Down
Loading

0 comments on commit 883d4c4

Please sign in to comment.