Skip to content

Commit

Permalink
Fix ci
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangpengcheng committed May 6, 2024
1 parent c33c5b1 commit ce455b7
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .ci/helm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ function ci::verify_elasticsearch_sink() {

function ci::verify_mongodb_source() {
timesleep=$1
kubectl exec mongo-dbz-0 -c mongo -- mongo -u debezium -p dbz --authenticationDatabase admin localhost:27017/inventory --eval 'db.products.update({"_id":NumberLong(104)},{$set:{weight:1.25}})'
kubectl exec mongo-dbz-0 -c mongo -- mongosh -u debezium -p dbz --authenticationDatabase admin localhost:27017/inventory --eval 'db.products.update({"_id":NumberLong(104)},{$set:{weight:1.25}})'
sleep "$timesleep"
kubectl logs --tail=-1 -l compute.functionmesh.io/name=source-sample | grep "records sent"
if [ $? -eq 0 ]; then
Expand Down
2 changes: 1 addition & 1 deletion .ci/tests/integration/cases/mongodb-source/verify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function install_mongodb_server() {
# install mongodb server
kubectl apply -f "${mongodb_file}"
num=0
while [[ ${num} -lt 3 ]]; do
while [[ ${num} -lt 1 ]]; do
sleep 5
kubectl get pods
num=$(kubectl get pods -l role=mongo | wc -l)
Expand Down
26 changes: 13 additions & 13 deletions controllers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,6 @@ func observeVPA(ctx context.Context, r client.Reader, name types.NamespacedName,
spec.UpdateVPAUpdatePolicy(updatePolicy, vpaSpec.ResourceUnit)
resourcePolicy := vpaSpec.ResourcePolicy
containerName := spec.GetVPAContainerName(&vpa.ObjectMeta)
if resourcePolicy == nil {
resourcePolicy = &vpav1.PodResourcePolicy{}
}
spec.UpdateResourcePolicy(resourcePolicy, containerName)
if !reflect.DeepEqual(updatePolicy, vpa.Spec.UpdatePolicy) ||
!reflect.DeepEqual(resourcePolicy, vpa.Spec.ResourcePolicy) {
Expand All @@ -147,18 +144,21 @@ func calculateVPARecommendation(vpa *vpav1.VerticalPodAutoscaler, vpaSpec *v1alp
if vpaSpec.ResourceUnit == nil || vpaSpec.ResourceUnit.CPU.MilliValue() == 0 && vpaSpec.ResourceUnit.Memory.MilliValue() == 0 {
return nil
}
containerName := spec.GetVPAContainerName(&vpa.ObjectMeta)
if vpa.Status.Recommendation != nil && vpa.Status.Recommendation.ContainerRecommendations != nil {
for _, recommend := range vpa.Status.Recommendation.ContainerRecommendations {
// set resource based on CPU
if recommend.Target.Cpu() != nil && recommend.Target.Cpu().Value() != 0 {
multiple = recommend.Target.Cpu().MilliValue() / vpaSpec.ResourceUnit.CPU.MilliValue()
if recommend.Target.Cpu().MilliValue()%vpaSpec.ResourceUnit.CPU.MilliValue() != 0 {
multiple += 1
}
} else if recommend.Target.Memory() != nil { // set resources based on Memory
multiple = recommend.Target.Memory().MilliValue() / vpaSpec.ResourceUnit.Memory.MilliValue()
if recommend.Target.Memory().MilliValue()%vpaSpec.ResourceUnit.Memory.MilliValue() != 0 {
multiple += 1
if containerName == recommend.ContainerName {
// set resource based on CPU
if recommend.Target.Cpu() != nil && recommend.Target.Cpu().Value() != 0 {
multiple = recommend.Target.Cpu().MilliValue() / vpaSpec.ResourceUnit.CPU.MilliValue()
if recommend.Target.Cpu().MilliValue()%vpaSpec.ResourceUnit.CPU.MilliValue() != 0 {
multiple += 1
}
} else if recommend.Target.Memory() != nil { // set resources based on Memory
multiple = recommend.Target.Memory().MilliValue() / vpaSpec.ResourceUnit.Memory.MilliValue()
if recommend.Target.Memory().MilliValue()%vpaSpec.ResourceUnit.Memory.MilliValue() != 0 {
multiple += 1
}
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions controllers/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func Test_calculateVPARecommendation(t *testing.T) {
Recommendation: &vpav1.RecommendedPodResources{
ContainerRecommendations: []vpav1.RecommendedContainerResources{
{
ContainerName: "*",
Target: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("0.2"),
corev1.ResourceMemory: resource.MustParse("1Gi"),
Expand Down Expand Up @@ -82,6 +83,7 @@ func Test_calculateVPARecommendation(t *testing.T) {
Recommendation: &vpav1.RecommendedPodResources{
ContainerRecommendations: []vpav1.RecommendedContainerResources{
{
ContainerName: "*",
Target: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("100m"),
corev1.ResourceMemory: resource.MustParse("1Gi"),
Expand Down Expand Up @@ -117,6 +119,7 @@ func Test_calculateVPARecommendation(t *testing.T) {
Recommendation: &vpav1.RecommendedPodResources{
ContainerRecommendations: []vpav1.RecommendedContainerResources{
{
ContainerName: "*",
Target: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("400m"),
corev1.ResourceMemory: resource.MustParse("1Gi"),
Expand Down Expand Up @@ -152,6 +155,7 @@ func Test_calculateVPARecommendation(t *testing.T) {
Recommendation: &vpav1.RecommendedPodResources{
ContainerRecommendations: []vpav1.RecommendedContainerResources{
{
ContainerName: "*",
Target: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("0.45"),
corev1.ResourceMemory: resource.MustParse("1Gi"),
Expand Down Expand Up @@ -187,6 +191,7 @@ func Test_calculateVPARecommendation(t *testing.T) {
Recommendation: &vpav1.RecommendedPodResources{
ContainerRecommendations: []vpav1.RecommendedContainerResources{
{
ContainerName: "*",
Target: corev1.ResourceList{
corev1.ResourceMemory: resource.MustParse("800Mi"),
},
Expand Down Expand Up @@ -221,6 +226,7 @@ func Test_calculateVPARecommendation(t *testing.T) {
Recommendation: &vpav1.RecommendedPodResources{
ContainerRecommendations: []vpav1.RecommendedContainerResources{
{
ContainerName: "*",
Target: corev1.ResourceList{
corev1.ResourceMemory: resource.MustParse("629145600"), // 600Mi
},
Expand Down Expand Up @@ -255,6 +261,7 @@ func Test_calculateVPARecommendation(t *testing.T) {
Recommendation: &vpav1.RecommendedPodResources{
ContainerRecommendations: []vpav1.RecommendedContainerResources{
{
ContainerName: "*",
Target: corev1.ResourceList{
corev1.ResourceMemory: resource.MustParse("1600Mi"),
},
Expand Down Expand Up @@ -289,6 +296,7 @@ func Test_calculateVPARecommendation(t *testing.T) {
Recommendation: &vpav1.RecommendedPodResources{
ContainerRecommendations: []vpav1.RecommendedContainerResources{
{
ContainerName: "*",
Target: corev1.ResourceList{
corev1.ResourceMemory: resource.MustParse("1.7Gi"),
},
Expand Down Expand Up @@ -323,6 +331,7 @@ func Test_calculateVPARecommendation(t *testing.T) {
Recommendation: &vpav1.RecommendedPodResources{
ContainerRecommendations: []vpav1.RecommendedContainerResources{
{
ContainerName: "*",
Target: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("200m"),
corev1.ResourceMemory: resource.MustParse("1Gi"),
Expand Down
26 changes: 11 additions & 15 deletions controllers/spec/vpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ func MakeVPA(objectMeta *metav1.ObjectMeta, targetRef *autov2.CrossVersionObject
objectMeta.Labels[LabelCustomResourceUnit] = "true"
}
resourcePolicy := vpa.ResourcePolicy
if resourcePolicy == nil {
resourcePolicy = &vpav1.PodResourcePolicy{}
}
UpdateResourcePolicy(resourcePolicy, containerName)

return &vpav1.VerticalPodAutoscaler{
Expand Down Expand Up @@ -78,9 +75,9 @@ func UpdateVPAUpdatePolicy(updatePolicy *vpav1.PodUpdatePolicy, resourceUnit *v1
}

func UpdateResourcePolicy(resourcePolicy *vpav1.PodResourcePolicy, containerName string) {
var containerPolicies []vpav1.ContainerResourcePolicy
containerScalingMode := vpav1.ContainerScalingModeAuto
if resourcePolicy != nil {
var containerPolicies []vpav1.ContainerResourcePolicy
containerScalingMode := vpav1.ContainerScalingModeAuto
if resourcePolicy.ContainerPolicies == nil {
resourcePolicy.ContainerPolicies = []vpav1.ContainerResourcePolicy{}
}
Expand All @@ -91,16 +88,15 @@ func UpdateResourcePolicy(resourcePolicy *vpav1.PodResourcePolicy, containerName
break
}
}
}

// if resource policy is not set, set the default policy, so the vpa policy won't be applied to other containers
if len(containerPolicies) == 0 {
containerPolicies = []vpav1.ContainerResourcePolicy{
{
ContainerName: containerName,
Mode: &containerScalingMode,
},
// if resource policy is not set, set the default policy, so the vpa policy won't be applied to other containers
if len(containerPolicies) == 0 {
containerPolicies = []vpav1.ContainerResourcePolicy{
{
ContainerName: containerName,
Mode: &containerScalingMode,
},
}
}
resourcePolicy.ContainerPolicies = containerPolicies
}
resourcePolicy.ContainerPolicies = containerPolicies
}

0 comments on commit ce455b7

Please sign in to comment.