mirror of
https://github.com/kubevela/kubevela.git
synced 2026-08-18 03:56:36 +00:00
Merge pull request #620 from wonderflow/golint
add description for export const variable and function
This commit is contained in:
@@ -34,10 +34,10 @@ type ApplicationDeploymentStatus struct {
|
||||
runtimev1alpha1.ConditionedStatus `json:",inline"`
|
||||
}
|
||||
|
||||
// ApplicationDeployment is the Schema for the ApplicationDeployment API
|
||||
// +kubebuilder:object:root=true
|
||||
// +kubebuilder:resource:categories={oam}
|
||||
// +kubebuilder:subresource:status
|
||||
// ApplicationDeployment is the Schema for the ApplicationDeployment API
|
||||
type ApplicationDeployment struct {
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
metav1.ObjectMeta `json:"metadata,omitempty"`
|
||||
@@ -46,8 +46,8 @@ type ApplicationDeployment struct {
|
||||
Status ApplicationDeploymentStatus `json:"status,omitempty"`
|
||||
}
|
||||
|
||||
// +kubebuilder:object:root=true
|
||||
// ApplicationDeploymentList contains a list of ApplicationDeployment
|
||||
// +kubebuilder:object:root=true
|
||||
type ApplicationDeploymentList struct {
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
metav1.ListMeta `json:"metadata,omitempty"`
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"k8s.io/client-go/rest"
|
||||
)
|
||||
|
||||
// Args is args for controller-runtime client
|
||||
type Args struct {
|
||||
Config *rest.Config
|
||||
Schema *runtime.Scheme
|
||||
|
||||
+18
-5
@@ -26,12 +26,14 @@ import (
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
)
|
||||
|
||||
// Source record the source of Capability
|
||||
type Source struct {
|
||||
RepoName string `json:"repoName"`
|
||||
ChartName string `json:"chartName,omitempty"`
|
||||
}
|
||||
|
||||
type CrdInfo struct {
|
||||
// CRDInfo record the CRD info of the Capability
|
||||
type CRDInfo struct {
|
||||
APIVersion string `json:"apiVersion"`
|
||||
Kind string `json:"kind"`
|
||||
}
|
||||
@@ -55,9 +57,10 @@ type Capability struct {
|
||||
// Plugin Source
|
||||
Source *Source `json:"source,omitempty"`
|
||||
Install *Installation `json:"install,omitempty"`
|
||||
CrdInfo *CrdInfo `json:"crdInfo,omitempty"`
|
||||
CrdInfo *CRDInfo `json:"crdInfo,omitempty"`
|
||||
}
|
||||
|
||||
// Chart defines all necessary information to install a whole chart
|
||||
type Chart struct {
|
||||
Repo string `json:"repo"`
|
||||
URL string `json:"url"`
|
||||
@@ -67,18 +70,25 @@ type Chart struct {
|
||||
Values map[string]interface{} `json:"values"`
|
||||
}
|
||||
|
||||
// Installation defines the installation method for this Capability, currently only helm is supported
|
||||
type Installation struct {
|
||||
Helm Chart `json:"helm"`
|
||||
//TODO(wonderflow) add raw yaml file support for install capability
|
||||
}
|
||||
|
||||
// CapType defines the type of capability
|
||||
type CapType string
|
||||
|
||||
const (
|
||||
// TypeWorkload represents OAM Workload
|
||||
TypeWorkload CapType = "workload"
|
||||
TypeTrait CapType = "trait"
|
||||
TypeScope CapType = "scope"
|
||||
// TypeTrait represents OAM Trait
|
||||
TypeTrait CapType = "trait"
|
||||
// TypeScope represent OAM Scope
|
||||
TypeScope CapType = "scope"
|
||||
)
|
||||
|
||||
// Parameter defines a parameter for cli from capability template
|
||||
type Parameter struct {
|
||||
Name string `json:"name"`
|
||||
Short string `json:"short,omitempty"`
|
||||
@@ -103,6 +113,7 @@ func ConvertTemplateJSON2Object(in *runtime.RawExtension) (Capability, error) {
|
||||
return t, err
|
||||
}
|
||||
|
||||
// SetFlagBy set cli flag from Parameter
|
||||
func SetFlagBy(flags *pflag.FlagSet, v Parameter) {
|
||||
name := v.Name
|
||||
if v.Alias != "" {
|
||||
@@ -142,6 +153,7 @@ func SetFlagBy(flags *pflag.FlagSet, v Parameter) {
|
||||
}
|
||||
}
|
||||
|
||||
// CapabilityCmpOptions will set compare option
|
||||
var CapabilityCmpOptions = []cmp.Option{
|
||||
cmp.Comparer(func(a, b Parameter) bool {
|
||||
if a.Name != b.Name || a.Short != b.Short || a.Required != b.Required ||
|
||||
@@ -186,7 +198,7 @@ var CapabilityCmpOptions = []cmp.Option{
|
||||
case int:
|
||||
va = float64(vala)
|
||||
case float64:
|
||||
va = float64(vala)
|
||||
va = vala
|
||||
}
|
||||
switch valb := b.Default.(type) {
|
||||
case int64:
|
||||
@@ -203,6 +215,7 @@ var CapabilityCmpOptions = []cmp.Option{
|
||||
return true
|
||||
})}
|
||||
|
||||
// EqualCapability will check whether two capabilities is equal
|
||||
func EqualCapability(a, b Capability) bool {
|
||||
return cmp.Equal(a, b, CapabilityCmpOptions...)
|
||||
}
|
||||
|
||||
+24
-15
@@ -1,26 +1,33 @@
|
||||
package types
|
||||
|
||||
const (
|
||||
DefaultOAMNS = "vela-system"
|
||||
DefaultOAMReleaseName = "kubevela"
|
||||
DefaultOAMRuntimeChartName = "vela-core"
|
||||
DefaultOAMVersion = ">0.0.0-0"
|
||||
|
||||
DefaultEnvName = "default"
|
||||
// DefaultKubeVelaNS defines the default KubeVela namespace in Kubernetes
|
||||
DefaultKubeVelaNS = "vela-system"
|
||||
// DefaultKubeVelaReleaseName defines the default name of KubeVela Release
|
||||
DefaultKubeVelaReleaseName = "kubevela"
|
||||
// DefaultKubeVelaChartName defines the default chart name of KubeVela, this variable MUST align to the chart name of this repo
|
||||
DefaultKubeVelaChartName = "vela-core"
|
||||
// DefaultKubeVelaVersion defines the default version needed for KubeVela chart
|
||||
DefaultKubeVelaVersion = ">0.0.0-0"
|
||||
// DefaultEnvName defines the default environment name for Apps created by KubeVela
|
||||
DefaultEnvName = "default"
|
||||
// DefaultAppNamespace defines the default K8s namespace for Apps created by KubeVela
|
||||
DefaultAppNamespace = "default"
|
||||
)
|
||||
|
||||
const (
|
||||
// AnnDescription is the annotation which describe what is the capability used for in a WorkloadDefinition/TraitDefinition Object
|
||||
AnnDescription = "definition.oam.dev/description"
|
||||
|
||||
LabelPodSpecable = "workload.oam.dev/podspecable"
|
||||
)
|
||||
|
||||
const (
|
||||
// StatusDeployed represents the App was deployed
|
||||
StatusDeployed = "Deployed"
|
||||
StatusStaging = "Staging"
|
||||
// StatusStaging represents the App was changed locally and it's spec is diff from the deployed one, or not deployed at all
|
||||
StatusStaging = "Staging"
|
||||
)
|
||||
|
||||
// EnvMeta stores the info for app environment
|
||||
type EnvMeta struct {
|
||||
Name string `json:"name"`
|
||||
Namespace string `json:"namespace"`
|
||||
@@ -33,12 +40,14 @@ type EnvMeta struct {
|
||||
}
|
||||
|
||||
const (
|
||||
// TagCommandType used for tag cli category
|
||||
TagCommandType = "commandType"
|
||||
|
||||
TypeStart = "Getting Started"
|
||||
TypeApp = "Managing Applications"
|
||||
TypeCap = "Managing Capabilities"
|
||||
// TypeStart defines one category
|
||||
TypeStart = "Getting Started"
|
||||
// TypeApp defines one category
|
||||
TypeApp = "Managing Applications"
|
||||
// TypeCap defines one category
|
||||
TypeCap = "Managing Capabilities"
|
||||
// TypeSystem defines one category
|
||||
TypeSystem = "System"
|
||||
|
||||
TypeTraits = "Traits"
|
||||
)
|
||||
|
||||
@@ -30,9 +30,9 @@ type Protocol string
|
||||
// TriggerType defines the type of trigger
|
||||
type TriggerType string
|
||||
|
||||
// Autoscaler is the Schema for the autoscalers API
|
||||
// +kubebuilder:object:root=true
|
||||
// +kubebuilder:resource:categories={oam}
|
||||
// Autoscaler is the Schema for the autoscalers API
|
||||
type Autoscaler struct {
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
metav1.ObjectMeta `json:"metadata,omitempty"`
|
||||
@@ -41,18 +41,22 @@ type Autoscaler struct {
|
||||
Status AutoscalerStatus `json:"status,omitempty"`
|
||||
}
|
||||
|
||||
// SetConditions set condition for CR status
|
||||
func (as *Autoscaler) SetConditions(c ...v1alpha1.Condition) {
|
||||
as.Status.SetConditions(c...)
|
||||
}
|
||||
|
||||
// GetCondition get condition from CR status
|
||||
func (as *Autoscaler) GetCondition(conditionType v1alpha1.ConditionType) v1alpha1.Condition {
|
||||
return as.Status.GetCondition(conditionType)
|
||||
}
|
||||
|
||||
// GetWorkloadReference get workload reference
|
||||
func (as *Autoscaler) GetWorkloadReference() v1alpha1.TypedReference {
|
||||
return as.Spec.WorkloadReference
|
||||
}
|
||||
|
||||
// SetWorkloadReference set workload reference
|
||||
func (as *Autoscaler) SetWorkloadReference(reference v1alpha1.TypedReference) {
|
||||
as.Spec.WorkloadReference = reference
|
||||
}
|
||||
|
||||
@@ -99,20 +99,22 @@ func init() {
|
||||
|
||||
var _ oam.Trait = &MetricsTrait{}
|
||||
|
||||
// SetConditions for set CR condition
|
||||
func (tr *MetricsTrait) SetConditions(c ...runtimev1alpha1.Condition) {
|
||||
tr.Status.SetConditions(c...)
|
||||
}
|
||||
|
||||
// GetCondition for get CR condition
|
||||
func (tr *MetricsTrait) GetCondition(c runtimev1alpha1.ConditionType) runtimev1alpha1.Condition {
|
||||
return tr.Status.GetCondition(c)
|
||||
}
|
||||
|
||||
// GetWorkloadReference of this ManualScalerTrait.
|
||||
// GetWorkloadReference of this MetricsTrait.
|
||||
func (tr *MetricsTrait) GetWorkloadReference() runtimev1alpha1.TypedReference {
|
||||
return tr.Spec.WorkloadReference
|
||||
}
|
||||
|
||||
// SetWorkloadReference of this ManualScalerTrait.
|
||||
// SetWorkloadReference of this MetricsTrait.
|
||||
func (tr *MetricsTrait) SetWorkloadReference(r runtimev1alpha1.TypedReference) {
|
||||
tr.Spec.WorkloadReference = r
|
||||
}
|
||||
|
||||
@@ -73,10 +73,12 @@ func init() {
|
||||
|
||||
var _ oam.Workload = &PodSpecWorkload{}
|
||||
|
||||
// SetConditions set condition for this CR
|
||||
func (in *PodSpecWorkload) SetConditions(c ...cpv1alpha1.Condition) {
|
||||
in.Status.SetConditions(c...)
|
||||
}
|
||||
|
||||
// GetCondition set condition for this CR
|
||||
func (in *PodSpecWorkload) GetCondition(c cpv1alpha1.ConditionType) cpv1alpha1.Condition {
|
||||
return in.Status.GetCondition(c)
|
||||
}
|
||||
|
||||
@@ -66,6 +66,7 @@ type Rule struct {
|
||||
Backend *Backend `json:"backend,omitempty"`
|
||||
}
|
||||
|
||||
// TLS defines certificate issuer and type for mTLS configuration
|
||||
type TLS struct {
|
||||
IssuerName string `json:"issuerName,omitempty"`
|
||||
|
||||
@@ -74,13 +75,17 @@ type TLS struct {
|
||||
Type IssuerType `json:"type,omitempty"`
|
||||
}
|
||||
|
||||
// IssuerType defines the type of issuer
|
||||
type IssuerType string
|
||||
|
||||
const (
|
||||
ClusterIssuer IssuerType = "ClusterIssuer"
|
||||
// ClusterIssuer is a cluster level type of issuer
|
||||
ClusterIssuer IssuerType = "ClusterIssuer"
|
||||
// NamespaceIssuer is the default one
|
||||
NamespaceIssuer IssuerType = "Issuer"
|
||||
)
|
||||
|
||||
// Backend defines backend configure for route trait.
|
||||
// Route will automatically discover podSpec and label for BackendService.
|
||||
// If BackendService is already set, discovery won't work.
|
||||
// If BackendService is not set, the discovery mechanism will work.
|
||||
@@ -109,10 +114,10 @@ type RouteStatus struct {
|
||||
runtimev1alpha1.ConditionedStatus `json:",inline"`
|
||||
}
|
||||
|
||||
// Route is the Schema for the routes API
|
||||
// +kubebuilder:object:root=true
|
||||
// +kubebuilder:resource:categories={oam}
|
||||
// +kubebuilder:subresource:status
|
||||
// Route is the Schema for the routes API
|
||||
type Route struct {
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
metav1.ObjectMeta `json:"metadata,omitempty"`
|
||||
@@ -121,8 +126,8 @@ type Route struct {
|
||||
Status RouteStatus `json:"status,omitempty"`
|
||||
}
|
||||
|
||||
// +kubebuilder:object:root=true
|
||||
// RouteList contains a list of Route
|
||||
// +kubebuilder:object:root=true
|
||||
type RouteList struct {
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
metav1.ListMeta `json:"metadata,omitempty"`
|
||||
@@ -135,20 +140,22 @@ func init() {
|
||||
|
||||
var _ oam.Trait = &Route{}
|
||||
|
||||
// SetConditions set condition for CR status
|
||||
func (r *Route) SetConditions(c ...runtimev1alpha1.Condition) {
|
||||
r.Status.SetConditions(c...)
|
||||
}
|
||||
|
||||
// GetCondition get condition from CR status
|
||||
func (r *Route) GetCondition(c runtimev1alpha1.ConditionType) runtimev1alpha1.Condition {
|
||||
return r.Status.GetCondition(c)
|
||||
}
|
||||
|
||||
// GetWorkloadReference of this ManualScalerTrait.
|
||||
// GetWorkloadReference of this Route Trait.
|
||||
func (r *Route) GetWorkloadReference() runtimev1alpha1.TypedReference {
|
||||
return r.Spec.WorkloadReference
|
||||
}
|
||||
|
||||
// SetWorkloadReference of this ManualScalerTrait.
|
||||
// SetWorkloadReference of this Route Trait.
|
||||
func (r *Route) SetWorkloadReference(rt runtimev1alpha1.TypedReference) {
|
||||
r.Spec.WorkloadReference = rt
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/crossplane/oam-kubernetes-runtime/pkg/oam/discoverymapper"
|
||||
|
||||
"github.com/gosuri/uitable"
|
||||
"github.com/spf13/cobra"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
|
||||
@@ -199,7 +199,7 @@ func OpenBrowser(url string) error {
|
||||
}
|
||||
|
||||
func CheckVelaRuntimeInstalledAndReady(ioStreams cmdutil.IOStreams, c client.Client) (bool, error) {
|
||||
if !helm.IsHelmReleaseRunning(types.DefaultOAMReleaseName, types.DefaultOAMRuntimeChartName, types.DefaultOAMNS, ioStreams) {
|
||||
if !helm.IsHelmReleaseRunning(types.DefaultKubeVelaReleaseName, types.DefaultKubeVelaChartName, types.DefaultKubeVelaNS, ioStreams) {
|
||||
ioStreams.Info(fmt.Sprintf("\n%s %s", emojiFail, "KubeVela runtime is not installed yet."))
|
||||
ioStreams.Info(fmt.Sprintf("\n%s %s%s or %s",
|
||||
emojiLightBulb,
|
||||
|
||||
@@ -30,7 +30,7 @@ func RefreshDefinitions(ctx context.Context, c types.Args, ioStreams cmdutil.IOS
|
||||
}
|
||||
var syncedTemplates []types.Capability
|
||||
|
||||
templates, templateErrors, err := plugins.GetWorkloadsFromCluster(ctx, types.DefaultOAMNS, c, dir, nil)
|
||||
templates, templateErrors, err := plugins.GetWorkloadsFromCluster(ctx, types.DefaultKubeVelaNS, c, dir, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -42,7 +42,7 @@ func RefreshDefinitions(ctx context.Context, c types.Args, ioStreams cmdutil.IOS
|
||||
syncedTemplates = append(syncedTemplates, templates...)
|
||||
plugins.SinkTemp2Local(templates, dir)
|
||||
|
||||
templates, templateErrors, err = plugins.GetTraitsFromCluster(ctx, types.DefaultOAMNS, c, dir, nil)
|
||||
templates, templateErrors, err = plugins.GetTraitsFromCluster(ctx, types.DefaultKubeVelaNS, c, dir, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
+12
-12
@@ -83,7 +83,7 @@ func NewAdminInfoCommand(ioStreams cmdutil.IOStreams) *cobra.Command {
|
||||
}
|
||||
|
||||
func (i *infoCmd) run(ioStreams cmdutil.IOStreams) error {
|
||||
clusterVersion, err := GetOAMReleaseVersion(types.DefaultOAMNS)
|
||||
clusterVersion, err := GetOAMReleaseVersion(types.DefaultKubeVelaNS)
|
||||
if err != nil {
|
||||
return fmt.Errorf("fail to get cluster chartPath: %v", err)
|
||||
}
|
||||
@@ -106,7 +106,7 @@ func NewInstallCommand(c types.Args, chartContent string, ioStreams cmdutil.IOSt
|
||||
return err
|
||||
}
|
||||
i.client = newClient
|
||||
i.namespace = types.DefaultOAMNS
|
||||
i.namespace = types.DefaultKubeVelaNS
|
||||
i.c = c
|
||||
return i.run(ioStreams, chartContent)
|
||||
},
|
||||
@@ -132,18 +132,18 @@ func (i *initCmd) run(ioStreams cmdutil.IOStreams, chartSource string) error {
|
||||
}
|
||||
|
||||
ioStreams.Info("- Installing Vela Core Chart:")
|
||||
exist, err := cmdutil.DoesNamespaceExist(i.client, types.DefaultOAMNS)
|
||||
exist, err := cmdutil.DoesNamespaceExist(i.client, types.DefaultKubeVelaNS)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !exist {
|
||||
if err := cmdutil.NewNamespace(i.client, types.DefaultOAMNS); err != nil {
|
||||
if err := cmdutil.NewNamespace(i.client, types.DefaultKubeVelaNS); err != nil {
|
||||
return err
|
||||
}
|
||||
ioStreams.Info("created namespace", types.DefaultOAMNS)
|
||||
ioStreams.Info("created namespace", types.DefaultKubeVelaNS)
|
||||
}
|
||||
|
||||
if helm.IsHelmReleaseRunning(types.DefaultOAMReleaseName, types.DefaultOAMRuntimeChartName, types.DefaultOAMNS, i.ioStreams) {
|
||||
if helm.IsHelmReleaseRunning(types.DefaultKubeVelaReleaseName, types.DefaultKubeVelaChartName, types.DefaultKubeVelaNS, i.ioStreams) {
|
||||
i.ioStreams.Info("Vela system along with OAM runtime already exist.")
|
||||
} else {
|
||||
vals, err := i.resolveValues()
|
||||
@@ -189,7 +189,7 @@ func CheckCapabilityReady(ctx context.Context, c types.Args, timeout time.Durati
|
||||
defer spiner.Stop()
|
||||
|
||||
for {
|
||||
_, err = plugins.GetCapabilitiesFromCluster(ctx, types.DefaultOAMNS, c, tmpdir, nil)
|
||||
_, err = plugins.GetCapabilitiesFromCluster(ctx, types.DefaultKubeVelaNS, c, tmpdir, nil)
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -233,7 +233,7 @@ func InstallOamRuntime(chartPath, chartSource string, vals map[string]interface{
|
||||
if err != nil {
|
||||
return fmt.Errorf("error loading chart for installation: %s", err)
|
||||
}
|
||||
installClient, err := helm.NewHelmInstall("", types.DefaultOAMNS, types.DefaultOAMReleaseName)
|
||||
installClient, err := helm.NewHelmInstall("", types.DefaultKubeVelaNS, types.DefaultKubeVelaReleaseName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error create helm install client: %s", err)
|
||||
}
|
||||
@@ -255,7 +255,7 @@ func GetOAMReleaseVersion(ns string) (string, error) {
|
||||
}
|
||||
|
||||
for _, result := range results {
|
||||
if result.Chart.ChartFullPath() == types.DefaultOAMRuntimeChartName {
|
||||
if result.Chart.ChartFullPath() == types.DefaultKubeVelaChartName {
|
||||
return result.Chart.AppVersion(), nil
|
||||
}
|
||||
}
|
||||
@@ -301,10 +301,10 @@ func PrintTrackVelaRuntimeStatus(ctx context.Context, c client.Client, ioStreams
|
||||
func getVelaRuntimeStatus(ctx context.Context, c client.Client) (VelaRuntimeStatus, string, error) {
|
||||
podList := &corev1.PodList{}
|
||||
opts := []client.ListOption{
|
||||
client.InNamespace(types.DefaultOAMNS),
|
||||
client.InNamespace(types.DefaultKubeVelaNS),
|
||||
client.MatchingLabels{
|
||||
"app.kubernetes.io/name": types.DefaultOAMRuntimeChartName,
|
||||
"app.kubernetes.io/instance": types.DefaultOAMReleaseName,
|
||||
"app.kubernetes.io/name": types.DefaultKubeVelaChartName,
|
||||
"app.kubernetes.io/instance": types.DefaultKubeVelaReleaseName,
|
||||
},
|
||||
}
|
||||
if err := c.List(ctx, podList, opts...); err != nil {
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
// IOStreams provides the standard names for iostreams. This is useful for embedding and for unit testing.
|
||||
@@ -18,41 +16,27 @@ type IOStreams struct {
|
||||
ErrOut io.Writer
|
||||
}
|
||||
|
||||
func PrintErrorMessage(errorMessage string, exitCode int) {
|
||||
fmt.Println(errorMessage)
|
||||
os.Exit(exitCode)
|
||||
}
|
||||
|
||||
// NewTestIOStreams returns a valid IOStreams and in, out, errout buffers for unit tests
|
||||
func NewTestIOStreams() (IOStreams, *bytes.Buffer, *bytes.Buffer, *bytes.Buffer) {
|
||||
in := &bytes.Buffer{}
|
||||
out := &bytes.Buffer{}
|
||||
errOut := &bytes.Buffer{}
|
||||
|
||||
return IOStreams{
|
||||
In: in,
|
||||
Out: out,
|
||||
ErrOut: errOut,
|
||||
}, in, out, errOut
|
||||
}
|
||||
|
||||
//Infonln compared to Info(), won't print new line
|
||||
// Infonln compared to Info(), won't print new line
|
||||
func (i *IOStreams) Infonln(a ...interface{}) {
|
||||
_, _ = i.Out.Write([]byte(fmt.Sprint(a...)))
|
||||
}
|
||||
|
||||
// Info print info with new line
|
||||
func (i *IOStreams) Info(a ...interface{}) {
|
||||
_, _ = i.Out.Write([]byte(fmt.Sprintln(a...)))
|
||||
}
|
||||
|
||||
// Infof print info in a specified format
|
||||
func (i *IOStreams) Infof(format string, a ...interface{}) {
|
||||
_, _ = i.Out.Write([]byte(fmt.Sprintf(format, a...)))
|
||||
}
|
||||
|
||||
// Errorf print error info in a specified format
|
||||
func (i *IOStreams) Errorf(format string, a ...interface{}) {
|
||||
_, _ = i.ErrOut.Write([]byte(fmt.Sprintf(format, a...)))
|
||||
}
|
||||
|
||||
// Error print error info
|
||||
func (i *IOStreams) Error(a ...interface{}) {
|
||||
_, _ = i.ErrOut.Write([]byte(fmt.Sprintln(a...)))
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@ var defaultCacheDir = filepath.Join(homedir.HomeDir(), ".kube", "http-cache")
|
||||
|
||||
var _ genericclioptions.RESTClientGetter = &restConfigGetter{}
|
||||
|
||||
// NewRestConfigGetter create config for helm client.
|
||||
// TODO(wonderflow): we should fix this hardcode client build,with restConfig as parameter.
|
||||
// The helm client never thought it could be used inside a cluster so it
|
||||
// took a dependency on the kube cli, we have to create a cli client getter from the rest.Config
|
||||
func NewRestConfigGetter(namespace string) genericclioptions.RESTClientGetter {
|
||||
|
||||
@@ -3,74 +3,19 @@ package util
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/AlecAivazis/survey/v2"
|
||||
corev1alpha2 "github.com/crossplane/oam-kubernetes-runtime/apis/core/v1alpha2"
|
||||
"github.com/spf13/cobra"
|
||||
"k8s.io/klog"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
)
|
||||
|
||||
const (
|
||||
DefaultErrorExitCode = 1
|
||||
)
|
||||
|
||||
func Print(msg string) {
|
||||
if klog.V(2) {
|
||||
klog.FatalDepth(2, msg)
|
||||
}
|
||||
if len(msg) > 0 {
|
||||
// add newline if needed
|
||||
if !strings.HasSuffix(msg, "\n") {
|
||||
msg += "\n"
|
||||
}
|
||||
fmt.Fprint(os.Stderr, msg)
|
||||
}
|
||||
}
|
||||
|
||||
func fatal(msg string, code int) {
|
||||
if klog.V(2) {
|
||||
klog.FatalDepth(2, msg)
|
||||
}
|
||||
if len(msg) > 0 {
|
||||
// add newline if needed
|
||||
if !strings.HasSuffix(msg, "\n") {
|
||||
msg += "\n"
|
||||
}
|
||||
fmt.Fprint(os.Stderr, msg)
|
||||
}
|
||||
os.Exit(code)
|
||||
}
|
||||
|
||||
func CheckErr(err error) {
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
msg := err.Error()
|
||||
if !strings.HasPrefix(msg, "error: ") {
|
||||
msg = fmt.Sprintf("error: %s", msg)
|
||||
}
|
||||
fatal(msg, DefaultErrorExitCode)
|
||||
}
|
||||
|
||||
// GetComponent get OAM component
|
||||
func GetComponent(ctx context.Context, c client.Client, componentName string, namespace string) (corev1alpha2.Component, error) {
|
||||
var component corev1alpha2.Component
|
||||
err := c.Get(ctx, client.ObjectKey{Name: componentName, Namespace: namespace}, &component)
|
||||
return component, err
|
||||
}
|
||||
|
||||
func PrintFlags(cmd *cobra.Command, subcmds []*cobra.Command) {
|
||||
cmd.Println("Flags:")
|
||||
for _, sub := range subcmds {
|
||||
if sub.HasLocalFlags() {
|
||||
cmd.Println(sub.LocalFlags().FlagUsages())
|
||||
}
|
||||
}
|
||||
cmd.Println()
|
||||
}
|
||||
|
||||
// AskToChooseOneService will ask users to select one service of the application if more than one exidi
|
||||
func AskToChooseOneService(svcNames []string) (string, error) {
|
||||
if len(svcNames) == 0 {
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
)
|
||||
|
||||
// OAMLabel defines the label of namespace automatically created by kubevela
|
||||
var OAMLabel = map[string]string{"app.kubernetes.io/part-of": "kubevela"}
|
||||
|
||||
// DoesNamespaceExist check namespace exist
|
||||
@@ -24,6 +25,7 @@ func DoesNamespaceExist(c client.Client, namespace string) (bool, error) {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// NewNamespace create namespace
|
||||
func NewNamespace(c client.Client, namespace string) error {
|
||||
ns := &v1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: namespace,
|
||||
// marking a special label for promethus monitoring.
|
||||
@@ -35,7 +37,7 @@ func NewNamespace(c client.Client, namespace string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// DoesCoreCRDExist check CRD exist
|
||||
// DoesCRDExist check CRD exist
|
||||
func DoesCRDExist(cxt context.Context, c client.Client, crdName string) (bool, error) {
|
||||
err := c.Get(cxt, types.NamespacedName{Name: crdName}, &apiextensions.CustomResourceDefinition{})
|
||||
if err != nil {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
//nolint
|
||||
package common
|
||||
|
||||
const (
|
||||
|
||||
@@ -6,6 +6,8 @@ import (
|
||||
v1 "k8s.io/api/core/v1"
|
||||
)
|
||||
|
||||
// ServiceKind is string "Service"
|
||||
var ServiceKind = reflect.TypeOf(v1.Service{}).Name()
|
||||
|
||||
// ServiceAPIVersion is string "v1"
|
||||
var ServiceAPIVersion = v1.SchemeGroupVersion.String()
|
||||
|
||||
@@ -23,6 +23,7 @@ type Reconciler struct {
|
||||
Scheme *runtime.Scheme
|
||||
}
|
||||
|
||||
// Reconcile is the main logci of applicationdeployment controller
|
||||
// +kubebuilder:rbac:groups=core.oam.dev,resources=applicationdeployments,verbs=get;list;watch;create;update;patch;delete
|
||||
// +kubebuilder:rbac:groups=core.oam.dev,resources=applicationdeployments/status,verbs=get;update;patch
|
||||
// +kubebuilder:rbac:groups=core.oam.dev,resources=applicationconfigurations,verbs=get;list;watch;create;update;patch;delete
|
||||
@@ -45,6 +46,7 @@ func (r *Reconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
|
||||
return ctrl.Result{}, nil
|
||||
}
|
||||
|
||||
// SetupWithManager setup the controller with manager
|
||||
func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
|
||||
r.record = event.NewAPIRecorder(mgr.GetEventRecorderFor("ApplicationDeployment")).
|
||||
WithAnnotations("controller", "ApplicationDeployment")
|
||||
|
||||
@@ -50,7 +50,7 @@ func init() {
|
||||
helmInstallFunc = helm.InstallHelmChart
|
||||
}
|
||||
|
||||
// Setup vela dependency.
|
||||
// Install will setup vela dependency.
|
||||
// Failing to install vela dependency should not block server from starting up.
|
||||
// Some users might fail to get charts due to network blockage. We should fix this in other ways.
|
||||
// Note: reconsider delegating the work to helm operator.
|
||||
@@ -77,6 +77,7 @@ func Install(kubecli client.Client) {
|
||||
}
|
||||
}
|
||||
|
||||
// nolint
|
||||
func Uninstall(kubecli client.Client) {
|
||||
velaConfig, err := fetchVelaConfig(kubecli)
|
||||
if err != nil {
|
||||
@@ -94,7 +95,7 @@ func Uninstall(kubecli client.Client) {
|
||||
}
|
||||
|
||||
func fetchVelaConfig(kubecli client.Client) (*v1.ConfigMap, error) {
|
||||
velaConfigNN := k8stypes.NamespacedName{Name: VelaConfigName, Namespace: types.DefaultOAMNS}
|
||||
velaConfigNN := k8stypes.NamespacedName{Name: VelaConfigName, Namespace: types.DefaultKubeVelaNS}
|
||||
velaConfig := &v1.ConfigMap{}
|
||||
if err := kubecli.Get(context.TODO(), velaConfigNN, velaConfig); err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -15,6 +15,8 @@ import (
|
||||
"github.com/oam-dev/kubevela/api/types"
|
||||
)
|
||||
|
||||
const LabelPodSpecable = "workload.oam.dev/podspecable"
|
||||
|
||||
func GetPodSpecPath(workloadDef *v1alpha2.WorkloadDefinition) (string, bool) {
|
||||
if workloadDef.Spec.PodSpecPath != "" {
|
||||
return workloadDef.Spec.PodSpecPath, true
|
||||
@@ -22,7 +24,7 @@ func GetPodSpecPath(workloadDef *v1alpha2.WorkloadDefinition) (string, bool) {
|
||||
if workloadDef.Labels == nil {
|
||||
return "", false
|
||||
}
|
||||
podSpecable, ok := workloadDef.Labels[types.LabelPodSpecable]
|
||||
podSpecable, ok := workloadDef.Labels[LabelPodSpecable]
|
||||
if !ok {
|
||||
return "", false
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ import (
|
||||
"github.com/oam-dev/kubevela/pkg/controller/common"
|
||||
)
|
||||
|
||||
// nolint:golint
|
||||
const (
|
||||
SpecWarningTargetWorkloadNotSet = "Spec.targetWorkload is not set"
|
||||
SpecWarningStartAtTimeFormat = "startAt is not in the right format, which should be like `12:01`"
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
//nolint:golint
|
||||
package autoscalers
|
||||
|
||||
import (
|
||||
|
||||
@@ -78,6 +78,7 @@ type Reconciler struct {
|
||||
record event.Recorder
|
||||
}
|
||||
|
||||
// Reconcile is the main logic for metric trait controller
|
||||
// +kubebuilder:rbac:groups=standard.oam.dev,resources=metricstraits,verbs=get;list;watch;create;update;patch;delete
|
||||
// +kubebuilder:rbac:groups=standard.oam.dev,resources=metricstraits/status,verbs=get;update;patch
|
||||
// +kubebuilder:rbac:groups=monitoring.coreos.com,resources=*,verbs=get;list;watch;create;update;patch;delete
|
||||
@@ -85,7 +86,6 @@ type Reconciler struct {
|
||||
// +kubebuilder:rbac:groups=core.oam.dev,resources=*,verbs=get;list;watch;create;update;patch;delete
|
||||
// +kubebuilder:rbac:groups=core.oam.dev,resources=*/status,verbs=get;
|
||||
// +kubebuilder:rbac:groups="",resources=events,verbs=get;list;create;update;patch
|
||||
|
||||
func (r *Reconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
|
||||
ctx := context.Background()
|
||||
mLog := r.Log.WithValues("metricstrait", req.NamespacedName)
|
||||
@@ -325,6 +325,7 @@ func constructServiceMonitor(metricsTrait *v1alpha1.MetricsTrait, targetPort int
|
||||
}
|
||||
}
|
||||
|
||||
// SetupWithManager setup Reconciler with ctrl.Manager
|
||||
func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
|
||||
r.record = event.NewAPIRecorder(mgr.GetEventRecorderFor("MetricsTrait")).
|
||||
WithAnnotations("controller", "metricsTrait")
|
||||
|
||||
@@ -10,18 +10,23 @@ import (
|
||||
standardv1alpha1 "github.com/oam-dev/kubevela/api/v1alpha1"
|
||||
)
|
||||
|
||||
// TypeNginx is a type of route implementation
|
||||
const TypeNginx = "nginx"
|
||||
|
||||
const (
|
||||
StatusReady = "Ready"
|
||||
// StatusReady represents status is ready
|
||||
StatusReady = "Ready"
|
||||
// StatusSynced represents status is synced, this mean the controller has reconciled but not ready
|
||||
StatusSynced = "Synced"
|
||||
)
|
||||
|
||||
// RouteIngress is an interface of route ingress implementation
|
||||
type RouteIngress interface {
|
||||
Construct(routeTrait *standardv1alpha1.Route) []*v1beta1.Ingress
|
||||
CheckStatus(routeTrait *standardv1alpha1.Route) (string, []runtimev1alpha1.Condition)
|
||||
}
|
||||
|
||||
// GetRouteIngress will get real implementation from type, we could support more in the future.
|
||||
func GetRouteIngress(provider string, client client.Client) (RouteIngress, error) {
|
||||
var routeIngress RouteIngress
|
||||
switch provider {
|
||||
|
||||
@@ -20,12 +20,14 @@ import (
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
)
|
||||
|
||||
// Nginx is nginx ingress implementation
|
||||
type Nginx struct {
|
||||
Client client.Client
|
||||
}
|
||||
|
||||
var _ RouteIngress = &Nginx{}
|
||||
|
||||
// CheckStatus will check status of the ingress
|
||||
func (n *Nginx) CheckStatus(routeTrait *standardv1alpha1.Route) (string, []runtimev1alpha1.Condition) {
|
||||
ctx := context.Background()
|
||||
// check issuer
|
||||
@@ -99,6 +101,7 @@ func (n *Nginx) CheckStatus(routeTrait *standardv1alpha1.Route) (string, []runti
|
||||
Reason: runtimev1alpha1.ReasonAvailable, LastTransitionTime: metav1.Now()}}
|
||||
}
|
||||
|
||||
// Construct will construct ingress from route
|
||||
func (*Nginx) Construct(routeTrait *standardv1alpha1.Route) []*v1beta1.Ingress {
|
||||
|
||||
// Don't create ingress if no host set, this is used for local K8s cluster demo and the route trait will create K8s service only.
|
||||
|
||||
@@ -64,6 +64,7 @@ type Reconciler struct {
|
||||
Scheme *runtime.Scheme
|
||||
}
|
||||
|
||||
// Reconcile is the main logic of controller
|
||||
// +kubebuilder:rbac:groups=standard.oam.dev,resources=routes,verbs=get;list;watch;create;update;patch;delete
|
||||
// +kubebuilder:rbac:groups=standard.oam.dev,resources=routes/status,verbs=get;update;patch
|
||||
func (r *Reconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
|
||||
@@ -248,7 +249,7 @@ func (r *Reconciler) fillBackendByCreatedService(ctx context.Context, mLog logr.
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Assume the workload or it's childResource will always having spec.template as PodTemplate if discoverable
|
||||
// DiscoverPortsLabel assume the workload or it's childResource will always having spec.template as PodTemplate if discoverable
|
||||
func DiscoverPortsLabel(ctx context.Context, workload *unstructured.Unstructured, r client.Reader, dm discoverymapper.DiscoveryMapper, childResources []*unstructured.Unstructured) ([]intstr.IntOrString, map[string]string, error) {
|
||||
|
||||
// here is the logic follows the design https://github.com/crossplane/oam-kubernetes-runtime/blob/master/design/one-pager-podspecable-workload.md#proposal
|
||||
@@ -309,6 +310,7 @@ func (r *Reconciler) fillBackendByCheckChildResource(mLog logr.Logger,
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetupWithManager setup with manager
|
||||
func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
|
||||
r.record = event.NewAPIRecorder(mgr.GetEventRecorderFor("Route")).
|
||||
WithAnnotations("controller", "route")
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
)
|
||||
|
||||
// NeedDiscovery checks the routeTrait Spec if it's needed to automatically discover
|
||||
func NeedDiscovery(routeTrait *v1alpha1.Route) bool {
|
||||
if len(routeTrait.Spec.Rules) == 0 {
|
||||
return true
|
||||
@@ -42,6 +43,7 @@ func MatchService(targetPort intstr.IntOrString, rule v1alpha1.Rule) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// FillRouteTraitWithService will use existing Service or created Service to fill the spec
|
||||
func FillRouteTraitWithService(service *corev1.Service, routeTrait *v1alpha1.Route) {
|
||||
if len(routeTrait.Spec.Rules) == 0 {
|
||||
routeTrait.Spec.Rules = []v1alpha1.Rule{{Name: "auto-created"}}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package cue
|
||||
|
||||
// BaseTemplate include base info provided by KubeVela for CUE template
|
||||
const BaseTemplate = `
|
||||
|
||||
context: {
|
||||
|
||||
@@ -57,6 +57,7 @@ func Eval(templatePath string, value map[string]interface{}) (*unstructured.Unst
|
||||
return &unstructured.Unstructured{Object: obj}, nil
|
||||
}
|
||||
|
||||
// GetParameters get parameter from cue template
|
||||
func GetParameters(templatePath string) ([]types.Parameter, error) {
|
||||
r := cue.Runtime{}
|
||||
b, err := ioutil.ReadFile(templatePath)
|
||||
@@ -136,6 +137,7 @@ func getDefaultByKind(k cue.Kind) interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetDefault evaluate default Go value from CUE
|
||||
func GetDefault(val cue.Value) interface{} {
|
||||
switch val.Kind() {
|
||||
case cue.IntKind:
|
||||
@@ -159,12 +161,15 @@ func GetDefault(val cue.Value) interface{} {
|
||||
}
|
||||
|
||||
const (
|
||||
// UsagePrefix defines the usage display for KubeVela CLI
|
||||
UsagePrefix = "+usage="
|
||||
// ShortPrefix defines the short argument for KubeVela CLI
|
||||
ShortPrefix = "+short="
|
||||
// AliasPrefix is an alias of the name of a parameter element, in order to making it more friendly to Cli users
|
||||
AliasPrefix = "+alias="
|
||||
)
|
||||
|
||||
// RetrieveComments will retrieve Usage, Short and Alias from CUE Value
|
||||
func RetrieveComments(value cue.Value) (string, string, string) {
|
||||
var short, usage, alias string
|
||||
docs := value.Doc()
|
||||
|
||||
@@ -94,7 +94,7 @@ func InstallCapability(client client.Client, mapper discoverymapper.DiscoveryMap
|
||||
if err = yaml.Unmarshal(workloadData, &wd); err != nil {
|
||||
return err
|
||||
}
|
||||
wd.Namespace = types.DefaultOAMNS
|
||||
wd.Namespace = types.DefaultKubeVelaNS
|
||||
ioStreams.Info("Installing workload capability " + wd.Name)
|
||||
if tp.Install != nil {
|
||||
tp.Source.ChartName = tp.Install.Helm.Name
|
||||
@@ -106,7 +106,7 @@ func InstallCapability(client client.Client, mapper discoverymapper.DiscoveryMap
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tp.CrdInfo = &types.CrdInfo{
|
||||
tp.CrdInfo = &types.CRDInfo{
|
||||
APIVersion: gvk.GroupVersion().String(),
|
||||
Kind: gvk.Kind,
|
||||
}
|
||||
@@ -122,7 +122,7 @@ func InstallCapability(client client.Client, mapper discoverymapper.DiscoveryMap
|
||||
if err = yaml.Unmarshal(traitdata, &td); err != nil {
|
||||
return err
|
||||
}
|
||||
td.Namespace = types.DefaultOAMNS
|
||||
td.Namespace = types.DefaultKubeVelaNS
|
||||
ioStreams.Info("Installing trait capability " + td.Name)
|
||||
if tp.Install != nil {
|
||||
tp.Source.ChartName = tp.Install.Helm.Name
|
||||
@@ -134,7 +134,7 @@ func InstallCapability(client client.Client, mapper discoverymapper.DiscoveryMap
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tp.CrdInfo = &types.CrdInfo{
|
||||
tp.CrdInfo = &types.CRDInfo{
|
||||
APIVersion: gvk.GroupVersion().String(),
|
||||
Kind: gvk.Kind,
|
||||
}
|
||||
@@ -246,9 +246,9 @@ func UninstallCap(client client.Client, cap types.Capability, ioStreams cmdutil.
|
||||
var obj runtime.Object
|
||||
switch cap.Type {
|
||||
case types.TypeTrait:
|
||||
obj = &v1alpha2.TraitDefinition{ObjectMeta: v1.ObjectMeta{Name: cap.Name, Namespace: types.DefaultOAMNS}}
|
||||
obj = &v1alpha2.TraitDefinition{ObjectMeta: v1.ObjectMeta{Name: cap.Name, Namespace: types.DefaultKubeVelaNS}}
|
||||
case types.TypeWorkload:
|
||||
obj = &v1alpha2.WorkloadDefinition{ObjectMeta: v1.ObjectMeta{Name: cap.Name, Namespace: types.DefaultOAMNS}}
|
||||
obj = &v1alpha2.WorkloadDefinition{ObjectMeta: v1.ObjectMeta{Name: cap.Name, Namespace: types.DefaultKubeVelaNS}}
|
||||
}
|
||||
if err := client.Delete(ctx, obj); err != nil {
|
||||
return err
|
||||
@@ -256,7 +256,7 @@ func UninstallCap(client client.Client, cap types.Capability, ioStreams cmdutil.
|
||||
|
||||
if cap.Install != nil && cap.Install.Helm.Name != "" {
|
||||
// 2. Remove Helm chart if there is
|
||||
if err := helm.Uninstall(ioStreams, cap.Install.Helm.Name, types.DefaultOAMNS, cap.Name); err != nil {
|
||||
if err := helm.Uninstall(ioStreams, cap.Install.Helm.Name, types.DefaultKubeVelaNS, cap.Name); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import (
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
)
|
||||
|
||||
// GithubContent for cap center
|
||||
type GithubContent struct {
|
||||
Owner string `json:"owner"`
|
||||
Repo string `json:"repo"`
|
||||
@@ -29,17 +30,19 @@ type GithubContent struct {
|
||||
Ref string `json:"ref"`
|
||||
}
|
||||
|
||||
//CapCenterConfig is used to store cap center config in file
|
||||
// CapCenterConfig is used to store cap center config in file
|
||||
type CapCenterConfig struct {
|
||||
Name string `json:"name"`
|
||||
Address string `json:"address"`
|
||||
Token string `json:"token"`
|
||||
}
|
||||
|
||||
// CenterClient defines an interface for cap center client
|
||||
type CenterClient interface {
|
||||
SyncCapabilityFromCenter() error
|
||||
}
|
||||
|
||||
// NewCenterClient create a client from type
|
||||
func NewCenterClient(ctx context.Context, name, address, token string) (CenterClient, error) {
|
||||
Type, cfg, err := Parse(address)
|
||||
if err != nil {
|
||||
@@ -52,9 +55,13 @@ func NewCenterClient(ctx context.Context, name, address, token string) (CenterCl
|
||||
return nil, errors.New("we only support github as repository now")
|
||||
}
|
||||
|
||||
// TypeGithub represents github
|
||||
const TypeGithub = "github"
|
||||
|
||||
// TypeUnknown represents parse failed
|
||||
const TypeUnknown = "unknown"
|
||||
|
||||
// Parse will parse config from address
|
||||
func Parse(addr string) (string, *GithubContent, error) {
|
||||
url, err := url.Parse(addr)
|
||||
if err != nil {
|
||||
@@ -105,6 +112,7 @@ func Parse(addr string) (string, *GithubContent, error) {
|
||||
return TypeUnknown, nil, nil
|
||||
}
|
||||
|
||||
// RemoteCapability defines the capability discovered from remote cap center
|
||||
type RemoteCapability struct {
|
||||
// Name MUST be xxx.yaml
|
||||
Name string `json:"name"`
|
||||
@@ -114,8 +122,10 @@ type RemoteCapability struct {
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
// RemoteCapabilities is slice of cap center
|
||||
type RemoteCapabilities []RemoteCapability
|
||||
|
||||
// LoadRepos will load all cap center repos
|
||||
//TODO(wonderflow): we can make default(built-in) repo configurable, then we should make default inside the answer
|
||||
func LoadRepos() ([]CapCenterConfig, error) {
|
||||
config, err := system.GetRepoConfig()
|
||||
@@ -136,6 +146,7 @@ func LoadRepos() ([]CapCenterConfig, error) {
|
||||
return repos, nil
|
||||
}
|
||||
|
||||
// StoreRepos will store cap center repo locally
|
||||
func StoreRepos(repos []CapCenterConfig) error {
|
||||
config, err := system.GetRepoConfig()
|
||||
if err != nil {
|
||||
@@ -148,6 +159,7 @@ func StoreRepos(repos []CapCenterConfig) error {
|
||||
return ioutil.WriteFile(config, data, 0644)
|
||||
}
|
||||
|
||||
// ParseAndSyncCapability will convert config from remote center to capability
|
||||
func ParseAndSyncCapability(data []byte, syncDir string) (types.Capability, error) {
|
||||
var obj = unstructured.Unstructured{Object: make(map[string]interface{})}
|
||||
err := yaml.Unmarshal(data, &obj.Object)
|
||||
@@ -175,6 +187,7 @@ func ParseAndSyncCapability(data []byte, syncDir string) (types.Capability, erro
|
||||
return types.Capability{}, fmt.Errorf("unknown definition Type %s", obj.GetKind())
|
||||
}
|
||||
|
||||
// GithubCenter implementation of cap center
|
||||
type GithubCenter struct {
|
||||
client *github.Client
|
||||
cfg *GithubContent
|
||||
@@ -184,6 +197,7 @@ type GithubCenter struct {
|
||||
|
||||
var _ CenterClient = &GithubCenter{}
|
||||
|
||||
// NewGithubCenter will create client by github center implementation
|
||||
func NewGithubCenter(ctx context.Context, token, centerName string, r *GithubContent) (*GithubCenter, error) {
|
||||
var tc *http.Client
|
||||
if token != "" {
|
||||
@@ -195,6 +209,7 @@ func NewGithubCenter(ctx context.Context, token, centerName string, r *GithubCon
|
||||
return &GithubCenter{client: github.NewClient(tc), cfg: r, centerName: centerName, ctx: ctx}, nil
|
||||
}
|
||||
|
||||
// SyncCapabilityFromCenter will sync capability from github cap center
|
||||
//TODO(wonderflow): currently we only sync by create, we also need to delete which not exist remotely.
|
||||
func (g *GithubCenter) SyncCapabilityFromCenter() error {
|
||||
_, dirs, _, err := g.client.Repositories.GetContents(g.ctx, g.cfg.Owner, g.cfg.Repo, g.cfg.Path, &github.RepositoryContentGetOptions{Ref: g.cfg.Ref})
|
||||
|
||||
@@ -23,8 +23,10 @@ import (
|
||||
"github.com/oam-dev/kubevela/pkg/utils/system"
|
||||
)
|
||||
|
||||
// nolint
|
||||
const DescriptionUndefined = "description not defined"
|
||||
|
||||
// GetCapabilitiesFromCluster will get capability from K8s cluster
|
||||
func GetCapabilitiesFromCluster(ctx context.Context, namespace string, c types.Args, syncDir string, selector labels.Selector) ([]types.Capability, error) {
|
||||
workloads, _, err := GetWorkloadsFromCluster(ctx, namespace, c, syncDir, selector)
|
||||
if err != nil {
|
||||
@@ -38,6 +40,7 @@ func GetCapabilitiesFromCluster(ctx context.Context, namespace string, c types.A
|
||||
return workloads, nil
|
||||
}
|
||||
|
||||
// GetWorkloadsFromCluster will get capability from K8s cluster
|
||||
func GetWorkloadsFromCluster(ctx context.Context, namespace string, c types.Args, syncDir string, selector labels.Selector) ([]types.Capability, []error, error) {
|
||||
newClient, err := client.New(c.Config, client.Options{Scheme: c.Schema})
|
||||
if err != nil {
|
||||
@@ -73,7 +76,7 @@ func GetWorkloadsFromCluster(ctx context.Context, namespace string, c types.Args
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("make sure you have installed CRD(controller) for this capability '%s': %v ", wd.Name, err)
|
||||
}
|
||||
tmp.CrdInfo = &types.CrdInfo{
|
||||
tmp.CrdInfo = &types.CRDInfo{
|
||||
APIVersion: gvk.GroupVersion().String(),
|
||||
Kind: gvk.Kind,
|
||||
}
|
||||
@@ -82,6 +85,7 @@ func GetWorkloadsFromCluster(ctx context.Context, namespace string, c types.Args
|
||||
return templates, templateErrors, nil
|
||||
}
|
||||
|
||||
// GetTraitsFromCluster will get capability from K8s cluster
|
||||
func GetTraitsFromCluster(ctx context.Context, namespace string, c types.Args, syncDir string, selector labels.Selector) ([]types.Capability, []error, error) {
|
||||
newClient, err := client.New(c.Config, client.Options{Scheme: c.Schema})
|
||||
if err != nil {
|
||||
@@ -116,7 +120,7 @@ func GetTraitsFromCluster(ctx context.Context, namespace string, c types.Args, s
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("make sure you have installed CRD(controller) for this capability '%s': %v ", td.Name, err)
|
||||
}
|
||||
tmp.CrdInfo = &types.CrdInfo{
|
||||
tmp.CrdInfo = &types.CRDInfo{
|
||||
APIVersion: gvk.GroupVersion().String(),
|
||||
Kind: gvk.Kind,
|
||||
}
|
||||
@@ -125,6 +129,7 @@ func GetTraitsFromCluster(ctx context.Context, namespace string, c types.Args, s
|
||||
return templates, templateErrors, nil
|
||||
}
|
||||
|
||||
// HandleDefinition will handle definition to capability
|
||||
func HandleDefinition(name, syncDir, crdName string, annotation map[string]string, extension *runtime.RawExtension, tp types.CapType, applyTo []string) (types.Capability, error) {
|
||||
var tmp types.Capability
|
||||
tmp, err := HandleTemplate(extension, name, syncDir)
|
||||
@@ -140,6 +145,7 @@ func HandleDefinition(name, syncDir, crdName string, annotation map[string]strin
|
||||
return tmp, nil
|
||||
}
|
||||
|
||||
// GetDescription get description from annotation
|
||||
func GetDescription(annotation map[string]string) string {
|
||||
if annotation == nil {
|
||||
return DescriptionUndefined
|
||||
@@ -151,6 +157,7 @@ func GetDescription(annotation map[string]string) string {
|
||||
return desc
|
||||
}
|
||||
|
||||
// HandleTemplate will handle definition template to capability
|
||||
func HandleTemplate(in *runtime.RawExtension, name, syncDir string) (types.Capability, error) {
|
||||
tmp, err := types.ConvertTemplateJSON2Object(in)
|
||||
if err != nil {
|
||||
|
||||
@@ -29,7 +29,7 @@ var _ = Describe("DefinitionFiles", func() {
|
||||
},
|
||||
Description: "description not defined",
|
||||
CrdName: "routes.standard.oam.dev",
|
||||
CrdInfo: &types.CrdInfo{
|
||||
CrdInfo: &types.CRDInfo{
|
||||
APIVersion: "standard.oam.dev/v1alpha1",
|
||||
Kind: "Route",
|
||||
},
|
||||
@@ -61,7 +61,7 @@ var _ = Describe("DefinitionFiles", func() {
|
||||
Usage: "Which port do you want customer traffic sent to",
|
||||
},
|
||||
},
|
||||
CrdInfo: &types.CrdInfo{
|
||||
CrdInfo: &types.CRDInfo{
|
||||
APIVersion: "apps/v1",
|
||||
Kind: "Deployment",
|
||||
},
|
||||
@@ -88,7 +88,7 @@ var _ = Describe("DefinitionFiles", func() {
|
||||
Usage: "Which port do you want customer traffic sent to",
|
||||
}},
|
||||
CrdName: "deployments.apps",
|
||||
CrdInfo: &types.CrdInfo{
|
||||
CrdInfo: &types.CRDInfo{
|
||||
APIVersion: "apps/v1",
|
||||
Kind: "Deployment",
|
||||
},
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/oam-dev/kubevela/pkg/utils/system"
|
||||
)
|
||||
|
||||
// LoadCapabilityByName will load capability from local by name
|
||||
func LoadCapabilityByName(name string) (types.Capability, error) {
|
||||
caps, err := LoadAllInstalledCapability()
|
||||
if err != nil {
|
||||
@@ -26,6 +27,7 @@ func LoadCapabilityByName(name string) (types.Capability, error) {
|
||||
return types.Capability{}, fmt.Errorf("%s not found", name)
|
||||
}
|
||||
|
||||
// LoadAllInstalledCapability will list all capability
|
||||
func LoadAllInstalledCapability() ([]types.Capability, error) {
|
||||
workloads, err := LoadInstalledCapabilityWithType(types.TypeWorkload)
|
||||
if err != nil {
|
||||
@@ -39,11 +41,13 @@ func LoadAllInstalledCapability() ([]types.Capability, error) {
|
||||
return workloads, nil
|
||||
}
|
||||
|
||||
// LoadInstalledCapabilityWithType will load cap list by type
|
||||
func LoadInstalledCapabilityWithType(capT types.CapType) ([]types.Capability, error) {
|
||||
dir, _ := system.GetCapabilityDir()
|
||||
return loadInstalledCapabilityWithType(dir, capT)
|
||||
}
|
||||
|
||||
// GetInstalledCapabilityWithCapAlias will get cap by alias
|
||||
func GetInstalledCapabilityWithCapAlias(capT types.CapType, capAlias string) (types.Capability, error) {
|
||||
dir, _ := system.GetCapabilityDir()
|
||||
return loadInstalledCapabilityWithCapAlias(dir, capT, capAlias)
|
||||
@@ -109,6 +113,7 @@ func loadInstalledCapability(dir string, capAlias string) ([]types.Capability, e
|
||||
return tmps, nil
|
||||
}
|
||||
|
||||
// GetSubDir will get dir for capability
|
||||
func GetSubDir(dir string, capT types.CapType) string {
|
||||
switch capT {
|
||||
case types.TypeWorkload:
|
||||
@@ -119,6 +124,7 @@ func GetSubDir(dir string, capT types.CapType) string {
|
||||
return dir
|
||||
}
|
||||
|
||||
// SinkTemp2Local will sink template to local file
|
||||
func SinkTemp2Local(templates []types.Capability, dir string) int {
|
||||
success := 0
|
||||
for _, tmp := range templates {
|
||||
@@ -174,6 +180,7 @@ func RemoveLegacyTemps(retainedTemps []types.Capability, dir string) int {
|
||||
return success
|
||||
}
|
||||
|
||||
// LoadCapabilityFromSyncedCenter will load capability from dir
|
||||
func LoadCapabilityFromSyncedCenter(dir string) ([]types.Capability, error) {
|
||||
var tmps []types.Capability
|
||||
files, err := ioutil.ReadDir(dir)
|
||||
|
||||
@@ -12,12 +12,14 @@ import (
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
)
|
||||
|
||||
// APIServer run a restful API server for dashboard
|
||||
type APIServer struct {
|
||||
server *http.Server
|
||||
KubeClient client.Client
|
||||
dm discoverymapper.DiscoveryMapper
|
||||
}
|
||||
|
||||
// New will create APIServer
|
||||
func New(c types.Args, port, staticPath string) (*APIServer, error) {
|
||||
newClient, err := client.New(c.Config, client.Options{Scheme: c.Schema})
|
||||
if err != nil {
|
||||
@@ -42,6 +44,7 @@ func New(c types.Args, port, staticPath string) (*APIServer, error) {
|
||||
return s, nil
|
||||
}
|
||||
|
||||
// Launch will start the apiserver
|
||||
func (s *APIServer) Launch(errChan chan<- error) {
|
||||
go func() {
|
||||
err := s.server.ListenAndServe()
|
||||
@@ -51,6 +54,7 @@ func (s *APIServer) Launch(errChan chan<- error) {
|
||||
}()
|
||||
}
|
||||
|
||||
// Shutdown will close the apiserver
|
||||
func (s *APIServer) Shutdown(ctx context.Context) error {
|
||||
ctrl.Log.Info("sever shutting down")
|
||||
return s.server.Shutdown(ctx)
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/oam-dev/kubevela/api/types"
|
||||
)
|
||||
|
||||
// Environment contains all info needed in `vela env` command
|
||||
type Environment struct {
|
||||
EnvName string `json:"envName" binding:"required,min=1,max=32"`
|
||||
Namespace string `json:"namespace" binding:"required,min=1,max=32"`
|
||||
@@ -15,27 +16,24 @@ type Environment struct {
|
||||
Current string `json:"current,omitempty"`
|
||||
}
|
||||
|
||||
// EnvironmentBody used for restful API in dashboard server
|
||||
type EnvironmentBody struct {
|
||||
Namespace string `json:"namespace" binding:"required,min=1,max=32"`
|
||||
}
|
||||
|
||||
type AppConfig struct {
|
||||
AppConfigName string `json:"appName" binding:"required,max=64"`
|
||||
Definition runtime.RawExtension `json:"definition" binding:"required"`
|
||||
DefinitionType string `json:"definitionType" binding:"required,max=32"`
|
||||
DefinitionName string `json:"definitionName" binding:"required,max=64"`
|
||||
}
|
||||
|
||||
// Response used for restful API response in dashboard server
|
||||
type Response struct {
|
||||
Code int `json:"code"`
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
|
||||
// CommonFlag used for restful API flags in dashboard server
|
||||
type CommonFlag struct {
|
||||
Name string `json:"name"`
|
||||
Value string `json:"value"`
|
||||
}
|
||||
|
||||
// WorkloadRunBody used for restful API arguments for run workload for dashboard restful API server
|
||||
type WorkloadRunBody struct {
|
||||
EnvName string `json:"envName"`
|
||||
WorkloadType string `json:"workloadType"`
|
||||
@@ -46,19 +44,21 @@ type WorkloadRunBody struct {
|
||||
Traits []TraitBody `json:"traits,omitempty"`
|
||||
}
|
||||
|
||||
// WorkloadMeta store workload metadata for dashboard restful API server
|
||||
type WorkloadMeta struct {
|
||||
Name string `json:"name"`
|
||||
Parameters []types.Parameter `json:"parameters,omitempty"`
|
||||
AppliesTo []string `json:"appliesTo,omitempty"`
|
||||
}
|
||||
|
||||
// TraitMeta store trait metadata for dashboard restful API server
|
||||
type TraitMeta struct {
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description,omitempty"`
|
||||
AppliesTo []string `json:"appliesTo,omitempty"`
|
||||
}
|
||||
|
||||
//used to present trait which is to be attached and, of which parameters are set
|
||||
// TraitBody used to present trait which is to be attached and, of which parameters are set
|
||||
type TraitBody struct {
|
||||
EnvName string `json:"envName"`
|
||||
Name string `json:"name"`
|
||||
@@ -68,6 +68,7 @@ type TraitBody struct {
|
||||
Staging string `json:"staging,omitempty"`
|
||||
}
|
||||
|
||||
// ComponentMeta store component info for dashboard restful API server
|
||||
type ComponentMeta struct {
|
||||
Name string `json:"name"`
|
||||
Status string `json:"status,omitempty"`
|
||||
@@ -83,6 +84,7 @@ type ComponentMeta struct {
|
||||
Component corev1alpha2.Component `json:"-"`
|
||||
}
|
||||
|
||||
// ApplicationMeta used for dashboard restful API server
|
||||
type ApplicationMeta struct {
|
||||
Name string `json:"name"`
|
||||
Status string `json:"status,omitempty"`
|
||||
@@ -90,11 +92,13 @@ type ApplicationMeta struct {
|
||||
CreatedTime string `json:"createdTime,omitempty"`
|
||||
}
|
||||
|
||||
// CapabilityMeta used for dashboard restful API server
|
||||
type CapabilityMeta struct {
|
||||
CapabilityName string `json:"capabilityName"`
|
||||
CapabilityCenterName string `json:"capabilityCenterName,omitempty"`
|
||||
}
|
||||
|
||||
// CapabilityCenterMeta used for dashboard restful API server
|
||||
type CapabilityCenterMeta struct {
|
||||
Name string `json:"name"`
|
||||
URL string `json:"url"`
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
//nolint:golint
|
||||
package util
|
||||
|
||||
import (
|
||||
|
||||
@@ -67,13 +67,14 @@ func ConstructError(ec Code, a ...interface{}) error {
|
||||
return errors.New(msg)
|
||||
}
|
||||
|
||||
// - use setErrorAndAbort to abort the rest of the handlers, mostly called in middleware
|
||||
// SetErrorAndAbort is used to abort the rest of the handlers, mostly called in middleware
|
||||
func SetErrorAndAbort(c *gin.Context, code Code, msg ...interface{}) {
|
||||
// Calling abort so no handlers and middlewares will be executed.
|
||||
c.AbortWithStatusJSON(code.StatusCode(), gin.H{"error": ConstructError(code, msg...).Error()})
|
||||
|
||||
}
|
||||
|
||||
// HandleError will handle error
|
||||
func HandleError(c *gin.Context, code Code, msg ...interface{}) {
|
||||
err := ConstructError(code, msg...)
|
||||
AssembleResponse(c, nil, err)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
//nolint:golint
|
||||
package util
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
//nolint: golint
|
||||
package server
|
||||
|
||||
import (
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
// Scheme defines the default KubeVela schema
|
||||
Scheme = k8sruntime.NewScheme()
|
||||
)
|
||||
|
||||
@@ -26,6 +27,7 @@ func init() {
|
||||
// +kubebuilder:scaffold:scheme
|
||||
}
|
||||
|
||||
// InitBaseRestConfig will return reset config for create controller runtime client
|
||||
func InitBaseRestConfig() (types.Args, error) {
|
||||
restConf, err := config.GetConfig()
|
||||
if err != nil {
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/oam-dev/kubevela/pkg/utils/env"
|
||||
)
|
||||
|
||||
// ReadConfigLine will read config from line
|
||||
func ReadConfigLine(line string) (string, string, error) {
|
||||
ss := strings.SplitN(line, ":", 2)
|
||||
if len(ss) != 2 {
|
||||
@@ -26,12 +27,14 @@ func ReadConfigLine(line string) (string, string, error) {
|
||||
return ss[0], string(vDec), nil
|
||||
}
|
||||
|
||||
// GetConfigsDir will get config from dir
|
||||
func GetConfigsDir(envName string) (string, error) {
|
||||
cfgDir := filepath.Join(env.GetEnvDirByName(envName), "configs")
|
||||
err := os.MkdirAll(cfgDir, 0700)
|
||||
return cfgDir, err
|
||||
}
|
||||
|
||||
// DeleteConfig will delete local config file
|
||||
func DeleteConfig(envName, configName string) error {
|
||||
d, err := GetConfigsDir(envName)
|
||||
if err != nil {
|
||||
@@ -41,6 +44,7 @@ func DeleteConfig(envName, configName string) error {
|
||||
return os.RemoveAll(cfgFile)
|
||||
}
|
||||
|
||||
// ReadConfig will read the config data from local
|
||||
func ReadConfig(envName, configName string) ([]byte, error) {
|
||||
d, err := GetConfigsDir(envName)
|
||||
if err != nil {
|
||||
@@ -54,6 +58,7 @@ func ReadConfig(envName, configName string) ([]byte, error) {
|
||||
return b, err
|
||||
}
|
||||
|
||||
// WriteConfig will write data into local config
|
||||
func WriteConfig(envName, configName string, data []byte) error {
|
||||
d, err := GetConfigsDir(envName)
|
||||
if err != nil {
|
||||
|
||||
Vendored
+12
-9
@@ -15,6 +15,7 @@ import (
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/utils/pointer"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
|
||||
"github.com/oam-dev/kubevela/api/types"
|
||||
@@ -24,11 +25,13 @@ import (
|
||||
// ProductionACMEServer is the production ACME Server from let's encrypt
|
||||
const ProductionACMEServer = "https://acme-v02.api.letsencrypt.org/directory"
|
||||
|
||||
// GetEnvDirByName will get env dir from name
|
||||
func GetEnvDirByName(name string) string {
|
||||
envdir, _ := system.GetEnvDir()
|
||||
return filepath.Join(envdir, name)
|
||||
}
|
||||
|
||||
// GetEnvByName will get env info by name
|
||||
func GetEnvByName(name string) (*types.EnvMeta, error) {
|
||||
data, err := ioutil.ReadFile(filepath.Join(GetEnvDirByName(name), system.EnvConfigName))
|
||||
if err != nil {
|
||||
@@ -44,9 +47,9 @@ func GetEnvByName(name string) (*types.EnvMeta, error) {
|
||||
return &meta, nil
|
||||
}
|
||||
|
||||
//Create or update env.
|
||||
//If it does not exist, create it and set to the new env.
|
||||
//If it exists, update it and set to the new env.
|
||||
// CreateOrUpdateEnv will create or update env.
|
||||
// If it does not exist, create it and set to the new env.
|
||||
// If it exists, update it and set to the new env.
|
||||
func CreateOrUpdateEnv(ctx context.Context, c client.Client, envName string, envArgs *types.EnvMeta) (string, error) {
|
||||
|
||||
createOrUpdated := "created"
|
||||
@@ -92,7 +95,7 @@ func CreateOrUpdateEnv(ctx context.Context, c client.Client, envName string, env
|
||||
},
|
||||
Solvers: []acmev1.ACMEChallengeSolver{{
|
||||
HTTP01: &acmev1.ACMEChallengeSolverHTTP01{
|
||||
Ingress: &acmev1.ACMEChallengeSolverHTTP01Ingress{Class: GetStringPointer("nginx")},
|
||||
Ingress: &acmev1.ACMEChallengeSolverHTTP01Ingress{Class: pointer.StringPtr("nginx")},
|
||||
},
|
||||
}},
|
||||
},
|
||||
@@ -134,10 +137,6 @@ func CreateOrUpdateEnv(ctx context.Context, c client.Client, envName string, env
|
||||
return message, nil
|
||||
}
|
||||
|
||||
func GetStringPointer(v string) *string {
|
||||
return &v
|
||||
}
|
||||
|
||||
// CreateEnv will only create. If env already exists, return error
|
||||
func CreateEnv(ctx context.Context, c client.Client, envName string, envArgs *types.EnvMeta) (string, error) {
|
||||
_, err := GetEnvByName(envName)
|
||||
@@ -148,7 +147,7 @@ func CreateEnv(ctx context.Context, c client.Client, envName string, envArgs *ty
|
||||
return CreateOrUpdateEnv(ctx, c, envName, envArgs)
|
||||
}
|
||||
|
||||
//Update Env, if env does not exist, return error
|
||||
// UpdateEnv will update Env, if env does not exist, return error
|
||||
func UpdateEnv(ctx context.Context, c client.Client, envName string, namespace string) (string, error) {
|
||||
var message = ""
|
||||
envMeta, err := GetEnvByName(envName)
|
||||
@@ -175,6 +174,7 @@ func UpdateEnv(ctx context.Context, c client.Client, envName string, namespace s
|
||||
return message, err
|
||||
}
|
||||
|
||||
// ListEnvs will list all envs
|
||||
func ListEnvs(envName string) ([]*types.EnvMeta, error) {
|
||||
var envList []*types.EnvMeta
|
||||
if envName != "" {
|
||||
@@ -220,6 +220,7 @@ func ListEnvs(envName string) ([]*types.EnvMeta, error) {
|
||||
return envList, nil
|
||||
}
|
||||
|
||||
// GetCurrentEnvName will get current env name
|
||||
func GetCurrentEnvName() (string, error) {
|
||||
currentEnvPath, err := system.GetCurrentEnvPath()
|
||||
if err != nil {
|
||||
@@ -232,6 +233,7 @@ func GetCurrentEnvName() (string, error) {
|
||||
return string(data), nil
|
||||
}
|
||||
|
||||
// DeleteEnv will delete env locally
|
||||
func DeleteEnv(envName string) (string, error) {
|
||||
var message string
|
||||
var err error
|
||||
@@ -261,6 +263,7 @@ func DeleteEnv(envName string) (string, error) {
|
||||
return message, err
|
||||
}
|
||||
|
||||
// SetEnv will set the current env to the specified one
|
||||
func SetEnv(envName string) (string, error) {
|
||||
var msg string
|
||||
currentEnvPath, err := system.GetCurrentEnvPath()
|
||||
|
||||
+15
-2
@@ -23,12 +23,14 @@ import (
|
||||
cmdutil "github.com/oam-dev/kubevela/pkg/commands/util"
|
||||
)
|
||||
|
||||
// VelaDebugLog defines an ENV to set vela helm install log to be debug
|
||||
const VelaDebugLog = "VELA_DEBUG"
|
||||
|
||||
var (
|
||||
settings = cli.New()
|
||||
)
|
||||
|
||||
// Install will install helm chart
|
||||
func Install(ioStreams cmdutil.IOStreams, repoName, repoURL, chartName, version, namespace, releaseName string,
|
||||
vals map[string]interface{}) error {
|
||||
|
||||
@@ -79,6 +81,7 @@ func Install(ioStreams cmdutil.IOStreams, repoName, repoURL, chartName, version,
|
||||
return nil
|
||||
}
|
||||
|
||||
// Uninstall will uninstall helm chart
|
||||
func Uninstall(ioStreams cmdutil.IOStreams, chartName, namespace, releaseName string) error {
|
||||
if !IsHelmReleaseRunning(releaseName, chartName, namespace, ioStreams) {
|
||||
return nil
|
||||
@@ -95,10 +98,11 @@ func Uninstall(ioStreams cmdutil.IOStreams, chartName, namespace, releaseName st
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewHelmInstall will create a install client for helm install
|
||||
func NewHelmInstall(version, namespace, releaseName string) (*action.Install, error) {
|
||||
actionConfig := new(action.Configuration)
|
||||
if len(namespace) == 0 {
|
||||
namespace = types.DefaultOAMNS
|
||||
namespace = types.DefaultKubeVelaNS
|
||||
}
|
||||
if err := actionConfig.Init(
|
||||
cmdutil.NewRestConfigGetter(namespace),
|
||||
@@ -117,11 +121,12 @@ func NewHelmInstall(version, namespace, releaseName string) (*action.Install, er
|
||||
if len(version) > 0 {
|
||||
client.Version = version
|
||||
} else {
|
||||
client.Version = types.DefaultOAMVersion
|
||||
client.Version = types.DefaultKubeVelaVersion
|
||||
}
|
||||
return client, nil
|
||||
}
|
||||
|
||||
// NewHelmUninstall will create a helm uninstall client
|
||||
func NewHelmUninstall(namespace string) (*action.Uninstall, error) {
|
||||
actionConfig := new(action.Configuration)
|
||||
|
||||
@@ -136,6 +141,7 @@ func NewHelmUninstall(namespace string) (*action.Uninstall, error) {
|
||||
return action.NewUninstall(actionConfig), nil
|
||||
}
|
||||
|
||||
// IsHelmRepositoryExist will check help repo exists
|
||||
func IsHelmRepositoryExist(name, url string) bool {
|
||||
repos := GetHelmRepositoryList()
|
||||
for _, repo := range repos {
|
||||
@@ -146,6 +152,7 @@ func IsHelmRepositoryExist(name, url string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// GetHelmRepositoryList get the helm repo list from default setting
|
||||
func GetHelmRepositoryList() []*repo.Entry {
|
||||
f, err := repo.LoadFile(settings.RepositoryConfig)
|
||||
if err == nil && len(f.Repositories) > 0 {
|
||||
@@ -153,6 +160,7 @@ func GetHelmRepositoryList() []*repo.Entry {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func debug(format string, v ...interface{}) {
|
||||
if settings.Debug {
|
||||
format = fmt.Sprintf("[debug] %s\n", format)
|
||||
@@ -160,6 +168,7 @@ func debug(format string, v ...interface{}) {
|
||||
}
|
||||
}
|
||||
|
||||
// AddHelmRepository add helm repo
|
||||
func AddHelmRepository(name, url, username, password, certFile, keyFile, caFile string, insecureSkipTLSverify bool, out io.Writer) error {
|
||||
var f repo.File
|
||||
c := repo.Entry{
|
||||
@@ -191,6 +200,7 @@ func AddHelmRepository(name, url, username, password, certFile, keyFile, caFile
|
||||
return nil
|
||||
}
|
||||
|
||||
// IsHelmReleaseRunning check helm release running
|
||||
func IsHelmReleaseRunning(releaseName, chartName, ns string, streams cmdutil.IOStreams) bool {
|
||||
releases, err := GetHelmRelease(ns)
|
||||
if err != nil {
|
||||
@@ -205,6 +215,7 @@ func IsHelmReleaseRunning(releaseName, chartName, ns string, streams cmdutil.IOS
|
||||
return false
|
||||
}
|
||||
|
||||
// GetHelmRelease will get helm release
|
||||
func GetHelmRelease(ns string) ([]*release.Release, error) {
|
||||
actionConfig := new(action.Configuration)
|
||||
client := action.NewList(actionConfig)
|
||||
@@ -220,6 +231,7 @@ func GetHelmRelease(ns string) ([]*release.Release, error) {
|
||||
return results, nil
|
||||
}
|
||||
|
||||
// GetChart will locate chart
|
||||
func GetChart(client *action.Install, name string) (*chart.Chart, error) {
|
||||
if os.Getenv(VelaDebugLog) != "" {
|
||||
settings.Debug = true
|
||||
@@ -237,6 +249,7 @@ func GetChart(client *action.Install, name string) (*chart.Chart, error) {
|
||||
return chartRequested, nil
|
||||
}
|
||||
|
||||
// InstallHelmChart will install helm chart from types.Chart
|
||||
func InstallHelmChart(ioStreams cmdutil.IOStreams, c types.Chart) error {
|
||||
return Install(ioStreams, c.Repo, c.URL, c.Name, c.Version, c.Namespace, c.Name, c.Values)
|
||||
}
|
||||
|
||||
@@ -10,8 +10,11 @@ import (
|
||||
)
|
||||
|
||||
const defaultVelaHome = ".vela"
|
||||
|
||||
// VelaHomeEnv defines vela home system env
|
||||
const VelaHomeEnv = "VELA_HOME"
|
||||
|
||||
// GetVelaHomeDir return vela home dir
|
||||
func GetVelaHomeDir() (string, error) {
|
||||
if custom := os.Getenv(VelaHomeEnv); custom != "" {
|
||||
return custom, nil
|
||||
@@ -23,6 +26,7 @@ func GetVelaHomeDir() (string, error) {
|
||||
return filepath.Join(home, defaultVelaHome), nil
|
||||
}
|
||||
|
||||
// GetDefaultFrontendDir return default vela frontend dir
|
||||
func GetDefaultFrontendDir() (string, error) {
|
||||
home, err := GetVelaHomeDir()
|
||||
if err != nil {
|
||||
@@ -31,6 +35,7 @@ func GetDefaultFrontendDir() (string, error) {
|
||||
return filepath.Join(home, "frontend"), nil
|
||||
}
|
||||
|
||||
// GetCapCenterDir return cap center dir
|
||||
func GetCapCenterDir() (string, error) {
|
||||
home, err := GetVelaHomeDir()
|
||||
if err != nil {
|
||||
@@ -39,6 +44,7 @@ func GetCapCenterDir() (string, error) {
|
||||
return filepath.Join(home, "centers"), nil
|
||||
}
|
||||
|
||||
// GetRepoConfig return repo config
|
||||
func GetRepoConfig() (string, error) {
|
||||
home, err := GetCapCenterDir()
|
||||
if err != nil {
|
||||
@@ -47,6 +53,7 @@ func GetRepoConfig() (string, error) {
|
||||
return filepath.Join(home, "config.yaml"), nil
|
||||
}
|
||||
|
||||
// GetCapabilityDir return capability dirs including workloads and traits
|
||||
func GetCapabilityDir() (string, error) {
|
||||
home, err := GetVelaHomeDir()
|
||||
if err != nil {
|
||||
@@ -55,6 +62,7 @@ func GetCapabilityDir() (string, error) {
|
||||
return filepath.Join(home, "capabilities"), nil
|
||||
}
|
||||
|
||||
// GetEnvDir return KubeVela environments dir
|
||||
func GetEnvDir() (string, error) {
|
||||
homedir, err := GetVelaHomeDir()
|
||||
if err != nil {
|
||||
@@ -63,6 +71,7 @@ func GetEnvDir() (string, error) {
|
||||
return filepath.Join(homedir, "envs"), nil
|
||||
}
|
||||
|
||||
// GetCurrentEnvPath return current env config
|
||||
func GetCurrentEnvPath() (string, error) {
|
||||
homedir, err := GetVelaHomeDir()
|
||||
if err != nil {
|
||||
@@ -71,6 +80,7 @@ func GetCurrentEnvPath() (string, error) {
|
||||
return filepath.Join(homedir, "curenv"), nil
|
||||
}
|
||||
|
||||
// InitDirs create dir if not exits
|
||||
func InitDirs() error {
|
||||
if err := InitCapabilityDir(); err != nil {
|
||||
return err
|
||||
@@ -84,6 +94,7 @@ func InitDirs() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// InitCapCenterDir create dir if not exits
|
||||
func InitCapCenterDir() error {
|
||||
home, err := GetCapCenterDir()
|
||||
if err != nil {
|
||||
@@ -93,6 +104,7 @@ func InitCapCenterDir() error {
|
||||
return err
|
||||
}
|
||||
|
||||
// InitCapabilityDir create dir if not exits
|
||||
func InitCapabilityDir() error {
|
||||
dir, err := GetCapabilityDir()
|
||||
if err != nil {
|
||||
@@ -102,8 +114,10 @@ func InitCapabilityDir() error {
|
||||
return err
|
||||
}
|
||||
|
||||
// EnvConfigName defines config
|
||||
const EnvConfigName = "config.json"
|
||||
|
||||
// InitDefaultEnv create dir if not exits
|
||||
func InitDefaultEnv() error {
|
||||
envDir, err := GetEnvDir()
|
||||
if err != nil {
|
||||
@@ -131,6 +145,7 @@ func InitDefaultEnv() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// CreateIfNotExist create dir if not exist
|
||||
func CreateIfNotExist(dir string) (bool, error) {
|
||||
_, err := os.Stat(dir)
|
||||
if err != nil {
|
||||
|
||||
@@ -66,7 +66,7 @@ func (h *MutatingHandler) Handle(ctx context.Context, req admission.Request) adm
|
||||
return resp
|
||||
}
|
||||
|
||||
// Default sets all the default value for the PodSpecWorkload
|
||||
// DefaultPodSpecWorkload will set the default value for the PodSpecWorkload
|
||||
func DefaultPodSpecWorkload(obj *v1alpha1.PodSpecWorkload) {
|
||||
mutatelog.Info("default", "name", obj.Name)
|
||||
if obj.Spec.Replicas == nil {
|
||||
|
||||
Reference in New Issue
Block a user