Skip to content

Commit

Permalink
Merge branch 'main' into cue-patch-provider
Browse files Browse the repository at this point in the history
  • Loading branch information
yangsoon committed Mar 30, 2023
2 parents c248dd3 + d7022ea commit b6c45af
Show file tree
Hide file tree
Showing 45 changed files with 3,371 additions and 75 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@
.idea/

.vscode
.history
.history

**apiserver.local.config/
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ unit-test:
lint:
golangci-lint run ./...

reviewable: fmt vet
reviewable: generate fmt vet tidy lint
6 changes: 6 additions & 0 deletions apis/cue/v1alpha1/package_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ import (

// Package is an extension for cuex engine
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:printcolumn:name="PATH",type=string,JSONPath=`.spec.path`
// +kubebuilder:printcolumn:name="PROTO",type=string,JSONPath=`.spec.provider.protocol`
// +kubebuilder:printcolumn:name="ENDPOINT",type=string,JSONPath=`.spec.provider.endpoint`
// +kubebuilder:resource:shortName={pkg,cpkg,cuepkg,cuepackage}
type Package struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand All @@ -44,6 +48,8 @@ const (
ProtocolGRPC ProviderProtocol = "grpc"
// ProtocolHTTP protocol type http for external Provider
ProtocolHTTP ProviderProtocol = "http"
// ProtocolHTTPS protocol type https for external Provider
ProtocolHTTPS ProviderProtocol = "https"
)

// Provider the external Provider in Package for cuex to run functions
Expand Down
2 changes: 1 addition & 1 deletion apis/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ limitations under the License.

// Generate deepcopy methodsets and CRD manifests
//go:generate go run -tags generate sigs.k8s.io/controller-tools/cmd/controller-gen object:headerFile=../hack/boilerplate.go.txt paths=./...
//go:generate go run -tags generate sigs.k8s.io/controller-tools/cmd/controller-gen object:headerFile=../hack/boilerplate.go.txt paths=./cue/... crd:crdVersions=v1,generateEmbeddedObjectMeta=true output:artifacts:config=../crds
//go:generate go run -tags generate sigs.k8s.io/controller-tools/cmd/controller-gen object:headerFile=../hack/boilerplate.go.txt paths=./... crd:crdVersions=v1,generateEmbeddedObjectMeta=true output:artifacts:config=../crds

package apis

Expand Down
51 changes: 51 additions & 0 deletions apis/oam/v1alpha1/definition_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
Copyright 2023 The KubeVela Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)

// Definition is a internal storage for KubeVela definitions, it will never be exposed directly to end users.
// It will just like a configmap as internal usage, using a standalone CRD can help us optimize the efficiency for informer.
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:printcolumn:name="TYPE",type=string,JSONPath=`.spec.type`
// +kubebuilder:resource:shortName={def}
type Definition struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec DefinitionSpec `json:"spec"`
}

// DefinitionSpec is the spec for definition
type DefinitionSpec struct {
Type string `json:"type"`
Templates map[string]string `json:"templates"`
// +nullable
Attributes *runtime.RawExtension `json:"attributes,omitempty"`
}

// DefinitionList list for Definition
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type DefinitionList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`

Items []Definition `json:"items"`
}
25 changes: 25 additions & 0 deletions apis/oam/v1alpha1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
Copyright 2023 The KubeVela Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Api versions allow the api contract for a resource to be changed while keeping
// backward compatibility by support multiple concurrent versions
// of the same resource

// Package v1alpha1 contains types required for v1alpha1
// +kubebuilder:object:generate=true
// +groupName=core.oam.dev
// +versionName=v1alpha1
package v1alpha1
52 changes: 52 additions & 0 deletions apis/oam/v1alpha1/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
Copyright 2021. The KubeVela Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
k8sscheme "k8s.io/client-go/kubernetes/scheme"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

const (
// Group .
Group = "core.oam.dev"
// Version .
Version = "v1alpha1"
)

var (
// SchemeGroupVersion is group version used to register these objects
SchemeGroupVersion = schema.GroupVersion{Group: Group, Version: Version}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion}

// AddToScheme is a global function that registers this API group & version to a scheme
AddToScheme = SchemeBuilder.AddToScheme
)

// Definition meta
var (
DefinitionKind = "Definition"
DefinitionGroupVersionKind = SchemeGroupVersion.WithKind(DefinitionKind)
)

func init() {
SchemeBuilder.Register(&Definition{}, &DefinitionList{})
_ = SchemeBuilder.AddToScheme(k8sscheme.Scheme)
}
111 changes: 111 additions & 0 deletions apis/oam/v1alpha1/zz_generated.deepcopy.go

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

2 changes: 1 addition & 1 deletion controller/client/monitor_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func monitor(ctx context.Context, verb string, obj runtime.Object) func() {
return func() {
v := time.Since(begin).Seconds()
controllerClientRequestLatency.WithLabelValues(
velaruntime.GetControllerInCaller(),
velaruntime.GetController(ctx),
cluster,
verb,
k8s.GetKindForObject(obj, true),
Expand Down
3 changes: 3 additions & 0 deletions controller/reconciler/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package reconciler
import (
"context"
"time"

"github.com/kubevela/pkg/util/runtime"
)

type contextKey int
Expand All @@ -34,6 +36,7 @@ var (

// NewReconcileContext create context with default timeout (60s)
func NewReconcileContext(ctx context.Context) (context.Context, context.CancelFunc) {
ctx = runtime.WithController(ctx, runtime.GetControllerInCaller())
return context.WithTimeout(WithBaseContext(ctx, ctx), ReconcileTimeout)
}

Expand Down
5 changes: 3 additions & 2 deletions controller/reconciler/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ import (
)

func TestReconcileContext(t *testing.T) {
baseCtx := context.Background()
baseCtx := context.WithValue(context.Background(), "base", "b")
t0 := time.Now().Add(ReconcileTimeout)
ctx, _ := NewReconcileContext(baseCtx)
_ctx, ok := BaseContextFrom(ctx)
require.True(t, ok)
require.Equal(t, baseCtx, _ctx)
b, _ := _ctx.Value("base").(string)
require.Equal(t, "b", b)
t1 := time.Now().Add(ReconcileTimeout)
ddl, ok := ctx.Deadline()
require.True(t, ok)
Expand Down
45 changes: 45 additions & 0 deletions controller/reconciler/ctrl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
Copyright 2023 The KubeVela Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package reconciler

import (
"k8s.io/apimachinery/pkg/runtime"

"github.com/kubevela/pkg/util/k8s"
)

const (
// LabelPause skip reconcile for objects that contains the label and with value "true"
LabelPause = "controller.core.oam.dev/pause"

// ValueTrue true value
ValueTrue = "true"
)

// SetPause set if the target object should skip reconcile
func SetPause(o runtime.Object, skip bool) {
if skip {
_ = k8s.AddLabel(o, LabelPause, ValueTrue)
return
}
_ = k8s.DeleteLabel(o, LabelPause)
}

// IsPaused check if the target object should skip reconcile
func IsPaused(o runtime.Object) bool {
return k8s.GetLabel(o, LabelPause) == ValueTrue
}
Loading

0 comments on commit b6c45af

Please sign in to comment.