Files
kubevela/pkg/webhook/core.oam.dev/v1alpha2/applicationrollout/common.go
T
Yue WangandGitHub 5a778b4732 add API v1beta1.ComponentManifest (#1814)
rfc appfile pkg: remove appConfig&component

fix unit test

rfc vela cli dryrun & livediff

fix unit test & e2e test

rfc app controller: remove appConfig&component

fix unit test & e2e test

fix rollout and webhook

fix use AppRevision as others' owner

move ComponentManifest to oam.types

add a util to make conversion between AppConfig and ComponentManifest

complete Component revision mechanism in app controller

add test for component revision

rename

fix unit tests

add clean up for component revision

fix unit test

Signed-off-by: roywang <seiwy2010@gmail.com>
2021-06-24 15:06:58 +08:00

74 lines
2.5 KiB
Go

/*
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 applicationrollout
import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"github.com/oam-dev/kubevela/apis/types"
"github.com/oam-dev/kubevela/pkg/controller/utils"
)
// FindCommonComponentWithManifest finds the common components in both the source and target workloads
// the source can be nil
func FindCommonComponentWithManifest(target, source map[string]*unstructured.Unstructured) []string {
var commonComponents []string
if source == nil {
for compName := range target {
commonComponents = append(commonComponents, compName)
}
return commonComponents
}
// find the common components in both the source and target components
// write an O(N) algorithm just for fun, totally doesn't worth the extra space
targetComponents := make(map[string]bool)
for comp := range target {
targetComponents[comp] = true
}
for comp := range source {
if targetComponents[comp] {
commonComponents = append(commonComponents, comp)
}
}
return commonComponents
}
// FindCommonComponent finds the common components in both the source and target application
// only used for rollout webhook, will delete after refactor rollout webhook
func FindCommonComponent(targetApp, sourceApp []*types.ComponentManifest) []string {
var commonComponents []string
if sourceApp == nil {
for _, comp := range targetApp {
commonComponents = append(commonComponents, utils.ExtractComponentName(comp.RevisionName))
}
return commonComponents
}
// find the common components in both the source and target application
// write an O(N) algorithm just for fun, totally doesn't worth the extra space
targetComponents := make(map[string]bool)
for _, comp := range targetApp {
targetComponents[utils.ExtractComponentName(comp.RevisionName)] = true
}
for _, comp := range sourceApp {
revisionName := utils.ExtractComponentName(comp.RevisionName)
if targetComponents[revisionName] {
commonComponents = append(commonComponents, revisionName)
}
}
return commonComponents
}