mirror of
https://github.com/kubevela/kubevela.git
synced 2026-08-19 04:26:39 +00:00
Chore: remove legacy rollout and scope (#6068)
* Chore: remove legacy rollout & scope Signed-off-by: Somefive <yd219913@alibaba-inc.com> * remove outdated params Signed-off-by: Somefive <yd219913@alibaba-inc.com> * fix Signed-off-by: Somefive <yd219913@alibaba-inc.com> --------- Signed-off-by: Somefive <yd219913@alibaba-inc.com>
This commit is contained in:
@@ -17,25 +17,14 @@ limitations under the License.
|
||||
package utils
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/mitchellh/hashstructure/v2"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
|
||||
"github.com/kubevela/workflow/pkg/cue/packages"
|
||||
|
||||
commontypes "github.com/oam-dev/kubevela/apis/core.oam.dev/common"
|
||||
"github.com/oam-dev/kubevela/apis/core.oam.dev/condition"
|
||||
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
|
||||
"github.com/oam-dev/kubevela/pkg/oam/util"
|
||||
)
|
||||
@@ -88,97 +77,3 @@ func ComputeSpecHash(spec interface{}) (string, error) {
|
||||
specHashLabel := strconv.FormatUint(specHash, 16)
|
||||
return specHashLabel, nil
|
||||
}
|
||||
|
||||
// RefreshPackageDiscover help refresh package discover
|
||||
// Deprecated: The function RefreshKubePackagesFromCluster affects performance and the code has been commented a long time.
|
||||
func RefreshPackageDiscover(ctx context.Context, k8sClient client.Client, pd *packages.PackageDiscover, definition runtime.Object) error {
|
||||
var gvk metav1.GroupVersionKind
|
||||
var err error
|
||||
switch def := definition.(type) {
|
||||
case *v1beta1.ComponentDefinition:
|
||||
if def.Spec.Workload.Definition == (commontypes.WorkloadGVK{}) {
|
||||
workloadDef := new(v1beta1.WorkloadDefinition)
|
||||
err = k8sClient.Get(ctx, client.ObjectKey{Name: def.Spec.Workload.Type, Namespace: def.Namespace}, workloadDef)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
gvk, err = util.GetGVKFromDefinition(k8sClient.RESTMapper(), workloadDef.Spec.Reference)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
gv, err := schema.ParseGroupVersion(def.Spec.Workload.Definition.APIVersion)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
gvk = metav1.GroupVersionKind{
|
||||
Group: gv.Group,
|
||||
Version: gv.Version,
|
||||
Kind: def.Spec.Workload.Definition.Kind,
|
||||
}
|
||||
}
|
||||
case *v1beta1.TraitDefinition:
|
||||
gvk, err = util.GetGVKFromDefinition(k8sClient.RESTMapper(), def.Spec.Reference)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
case *v1beta1.PolicyDefinition:
|
||||
gvk, err = util.GetGVKFromDefinition(k8sClient.RESTMapper(), def.Spec.Reference)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
case *v1beta1.WorkflowStepDefinition:
|
||||
gvk, err = util.GetGVKFromDefinition(k8sClient.RESTMapper(), def.Spec.Reference)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
default:
|
||||
}
|
||||
targetGVK := metav1.GroupVersionKind{
|
||||
Group: gvk.Group,
|
||||
Version: gvk.Version,
|
||||
Kind: gvk.Kind,
|
||||
}
|
||||
if exist := pd.Exist(targetGVK); exist {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := pd.RefreshKubePackagesFromCluster(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Test whether the refresh is successful
|
||||
// if exist := pd.Exist(targetGVK); !exist {
|
||||
// return fmt.Errorf("get CRD %s error", targetGVK.String())
|
||||
// }
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetUnstructuredObjectStatusCondition returns the status.condition with matching condType from an unstructured object.
|
||||
func GetUnstructuredObjectStatusCondition(obj *unstructured.Unstructured, condType string) (*condition.Condition, bool, error) {
|
||||
cs, found, err := unstructured.NestedSlice(obj.Object, "status", "conditions")
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
if !found {
|
||||
return nil, false, nil
|
||||
}
|
||||
for _, c := range cs {
|
||||
b, err := json.Marshal(c)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
condObj := &condition.Condition{}
|
||||
err = json.Unmarshal(b, condObj)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
if string(condObj.Type) != condType {
|
||||
continue
|
||||
}
|
||||
return condObj, true, nil
|
||||
}
|
||||
|
||||
return nil, false, nil
|
||||
}
|
||||
|
||||
@@ -18,15 +18,12 @@ package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/oam-dev/kubevela/apis/core.oam.dev/common"
|
||||
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
|
||||
"github.com/oam-dev/kubevela/pkg/oam"
|
||||
oamutil "github.com/oam-dev/kubevela/pkg/oam/util"
|
||||
)
|
||||
|
||||
func TestConstructExtract(t *testing.T) {
|
||||
@@ -74,26 +71,4 @@ func TestGetAppRevison(t *testing.T) {
|
||||
revisionName, latestRevision = GetAppNextRevision(app)
|
||||
assert.Equal(t, revisionName, "myapp-v2")
|
||||
assert.Equal(t, latestRevision, int64(2))
|
||||
// we generate new revisions if the app is rolling
|
||||
app.SetAnnotations(map[string]string{oam.AnnotationAppRollout: strconv.FormatBool(true)})
|
||||
revisionName, latestRevision = GetAppNextRevision(app)
|
||||
assert.Equal(t, revisionName, "myapp-v2")
|
||||
assert.Equal(t, latestRevision, int64(2))
|
||||
app.Status.LatestRevision = &common.Revision{
|
||||
Name: revisionName,
|
||||
Revision: latestRevision,
|
||||
}
|
||||
// try again
|
||||
revisionName, latestRevision = GetAppNextRevision(app)
|
||||
assert.Equal(t, revisionName, "myapp-v3")
|
||||
assert.Equal(t, latestRevision, int64(3))
|
||||
app.Status.LatestRevision = &common.Revision{
|
||||
Name: revisionName,
|
||||
Revision: latestRevision,
|
||||
}
|
||||
// remove the annotation and it will still advance
|
||||
oamutil.RemoveAnnotations(app, []string{oam.AnnotationAppRollout})
|
||||
revisionName, latestRevision = GetAppNextRevision(app)
|
||||
assert.Equal(t, revisionName, "myapp-v4")
|
||||
assert.Equal(t, latestRevision, int64(4))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user