Skip to content

Commit

Permalink
Fix ci
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangpengcheng committed May 7, 2024
1 parent ce455b7 commit 72ab88a
Show file tree
Hide file tree
Showing 4 changed files with 241 additions and 31 deletions.
16 changes: 16 additions & 0 deletions .ci/tests/integration/e2e_with_tls.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ setup:
label-selector: app=cert-manager
for: condition=Ready

- name: setup vpa
command: |
helm repo add cowboysysop https://cowboysysop.github.io/charts/
helm repo update
helm install vpa cowboysysop/vertical-pod-autoscaler
wait:
- namespace: default
resource: pod
label-selector: app.kubernetes.io/name=vertical-pod-autoscaler
for: condition=Ready

- name: install pulsar cluster
command: |
helm repo add streamnative https://charts.streamnative.io
Expand All @@ -37,6 +48,11 @@ setup:
helm dependency update charts/pulsar
helm install ${PULSAR_RELEASE_NAME} --set initialize=true --values ../.ci/clusters/values_skywalking_e2e_cluster_with_tls.yaml charts/pulsar
- name: install metrics service
command: |
kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
kubectl patch -n kube-system deployment metrics-server --type=json -p '[{"op":"add","path":"/spec/template/spec/containers/0/args/-","value":"--kubelet-insecure-tls"}]'
- name: wait for pulsar cluster ready
command: |
echo "wait until pulsar init job is completed"
Expand Down
6 changes: 2 additions & 4 deletions controllers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,9 @@ func observeVPA(ctx context.Context, r client.Reader, name types.NamespacedName,
}

// compare exists VPA with new Spec
updatePolicy := vpaSpec.UpdatePolicy
spec.UpdateVPAUpdatePolicy(updatePolicy, vpaSpec.ResourceUnit)
resourcePolicy := vpaSpec.ResourcePolicy
updatePolicy := spec.UpdateVPAUpdatePolicy(vpaSpec.UpdatePolicy, vpaSpec.ResourceUnit)
containerName := spec.GetVPAContainerName(&vpa.ObjectMeta)
spec.UpdateResourcePolicy(resourcePolicy, containerName)
resourcePolicy := spec.UpdateResourcePolicy(vpaSpec.ResourcePolicy, containerName)
if !reflect.DeepEqual(updatePolicy, vpa.Spec.UpdatePolicy) ||
!reflect.DeepEqual(resourcePolicy, vpa.Spec.ResourcePolicy) {
condition.Status = metav1.ConditionFalse
Expand Down
49 changes: 29 additions & 20 deletions controllers/spec/vpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@ import (

func MakeVPA(objectMeta *metav1.ObjectMeta, targetRef *autov2.CrossVersionObjectReference, vpa *v1alpha1.VPASpec) *vpav1.VerticalPodAutoscaler {
containerName := GetVPAContainerName(objectMeta)
updatePolicy := vpa.UpdatePolicy
UpdateVPAUpdatePolicy(updatePolicy, vpa.ResourceUnit)
updatePolicy := UpdateVPAUpdatePolicy(vpa.UpdatePolicy, vpa.ResourceUnit)
if vpa.ResourceUnit != nil {
objectMeta.Labels[LabelCustomResourceUnit] = "true"
}
resourcePolicy := vpa.ResourcePolicy
UpdateResourcePolicy(resourcePolicy, containerName)
resourcePolicy := UpdateResourcePolicy(vpa.ResourcePolicy, containerName)

return &vpav1.VerticalPodAutoscaler{
TypeMeta: metav1.TypeMeta{
Expand Down Expand Up @@ -67,19 +65,24 @@ func GetVPAContainerName(objectMeta *metav1.ObjectMeta) string {
return containerName
}

func UpdateVPAUpdatePolicy(updatePolicy *vpav1.PodUpdatePolicy, resourceUnit *v1alpha1.ResourceUnit) {
if updatePolicy != nil && resourceUnit != nil {
func UpdateVPAUpdatePolicy(updatePolicy *vpav1.PodUpdatePolicy, resourceUnit *v1alpha1.ResourceUnit) *vpav1.PodUpdatePolicy {
resultUpdatePolicy := updatePolicy
if resourceUnit != nil {
if resultUpdatePolicy == nil {
resultUpdatePolicy = &vpav1.PodUpdatePolicy{}
}
off := vpav1.UpdateModeOff
updatePolicy.UpdateMode = &off
resultUpdatePolicy.UpdateMode = &off
}
return resultUpdatePolicy
}

func UpdateResourcePolicy(resourcePolicy *vpav1.PodResourcePolicy, containerName string) {
func UpdateResourcePolicy(resourcePolicy *vpav1.PodResourcePolicy, containerName string) *vpav1.PodResourcePolicy {
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{}
containerPolicies = []vpav1.ContainerResourcePolicy{}
}
for _, policy := range resourcePolicy.ContainerPolicies {
if policy.ContainerName == containerName {
Expand All @@ -88,15 +91,21 @@ 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
}
resultResourcePolicy := resourcePolicy
if resultResourcePolicy == nil {
resultResourcePolicy = &vpav1.PodResourcePolicy{}
}
resultResourcePolicy.ContainerPolicies = containerPolicies
return resultResourcePolicy
}
Loading

0 comments on commit 72ab88a

Please sign in to comment.