Skip to content

Commit

Permalink
feat: add common helm wrap
Browse files Browse the repository at this point in the history
Signed-off-by: Abirdcfly <[email protected]>
  • Loading branch information
Abirdcfly committed Sep 19, 2023
1 parent 57d54a7 commit a4264f6
Show file tree
Hide file tree
Showing 9 changed files with 1,302 additions and 764 deletions.
45 changes: 27 additions & 18 deletions config/samples/example-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# 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.
#

if [[ $RUNNER_DEBUG -eq 1 ]] || [[ $GITHUB_RUN_ATTEMPT -gt 1 ]]; then
# use [debug logging](https://docs.github.com/en/actions/monitoring-and-troubleshooting-workflows/enabling-debug-logging)
# or run the same test multiple times.
Expand Down Expand Up @@ -130,12 +130,21 @@ function waitComponentStatus() {
while true; do
versions=$(kubectl -n${namespace} get components.core.kubebb.k8s.com.cn ${componentName} --ignore-not-found=true -ojson | jq -r '.status.versions|length')
if [[ $versions -ne 0 ]]; then
echo "component ${componentName} already have version information and can be installed"
break
# info "component:${componentName} already have version information and can be installed"
latest_version=$(kubectl -n${namespace} get components.core.kubebb.k8s.com.cn ${componentName} --ignore-not-found=true -ojson | jq -r '.status.versions[0].version')
if [[ $latest_version != "" ]]; then
# info "component:${componentName} already have version:${latest_version}, try to get image info and values.yaml info for this version..."
images=$(kubectl -n${namespace} get cm ${componentName}-${latest_version} --ignore-not-found=true -o json | jq -r '.data.images')
value=$(kubectl -n${namespace} get cm ${componentName}-${latest_version} --ignore-not-found=true -o json | jq -r '.data."values.yaml"')
if [[ $images != "" ]] && [[ $value != "" ]]; then
info "component:${componentName} version:${latest_version}, has image info:${images}, and values.yaml info:${value:0:10} ..."
break
fi
fi
fi
CURRENT_TIME=$(date +%s)
ELAPSED_TIME=$((CURRENT_TIME - START_TIME))
if [ $ELAPSED_TIME -gt $TimeoutSeconds ]; then
if [ $ELAPSED_TIME -gt 3600 ]; then
error "Timeout reached"
kubectl -n${namespace} get components
exit 1
Expand All @@ -151,7 +160,7 @@ function waitComponentPlanDone() {
while true; do
doneConds=$(kubectl -n${namespace} get ComponentPlan ${componentPlanName} --ignore-not-found=true -ojson | jq -r '.status.conditions' | jq 'map(select(.type == "Succeeded"))|map(select(.status == "True"))|length')
if [[ $doneConds -ne 0 ]]; then
echo "componentPlan ${componentPlanName} done"
info "componentPlan:${componentPlanName} done"
break
fi

Expand All @@ -173,7 +182,7 @@ function waitPodReady() {
while true; do
readStatus=$(kubectl -n${namespace} get po -l ${podLabel} --ignore-not-found=true -o json | jq -r '.items[0].status.conditions[] | select(."type"=="Ready") | .status')
if [[ $readStatus == "True" ]]; then
echo "Pod ${podLabel} ready"
info "Pod:${podLabel} ready"
kubectl -n${namespace} get po -l ${podLabel}
break
fi
Expand All @@ -197,14 +206,14 @@ function deleteComponentPlan() {
START_TIME=$(date +%s)
helmReleaseName=$(kubectl get ComponentPlan -n${namespace} ${componentPlanName} --ignore-not-found=true -ojson | jq -r '.spec.name')
if [[ $helmReleaseName == "" ]]; then
echo "componentPlan ${componentPlanName} has no release name"
info "componentPlan:${componentPlanName} has no release name"
kubectl get ComponentPlan -n${namespace} ${componentPlanName} -oyaml
exit 1
fi
while true; do
kubectl -n${namespace} delete ComponentPlan ${componentPlanName} --wait --ignore-not-found=true
if [[ $? -eq 0 ]]; then
echo "delete componentPlan ${componentPlanName} done"
info "delete componentPlan:${componentPlanName} done"
break
fi

Expand All @@ -219,10 +228,10 @@ function deleteComponentPlan() {
while true; do
results=$(helm status -n ${namespace} ${helmReleaseName})
if [[ $helmReleaseShouldDelete == "true" ]] && [[ $results == "" ]]; then
echo "helm release should remove, and helm status also show componentplan:${componentPlanName} 's release:${helmReleaseName} removed"
info "helm release should remove, and helm status also show componentplan:${componentPlanName} 's release:${helmReleaseName} removed"
break
elif [[ $helmReleaseShouldDelete == "false" ]] && [[ $results != "" ]]; then
echo "helm release should not remove, and helm status also show componentplan:${componentPlanName} 's release:${helmReleaseName} not removed"
info "helm release should not remove, and helm status also show componentplan:${componentPlanName} 's release:${helmReleaseName} not removed"
break
fi

Expand All @@ -246,7 +255,7 @@ function getPodImage() {
while true; do
images=$(kubectl -n${namespace} get po -l ${podLabel} --ignore-not-found=true -o json | jq -r '.items[0].status.containerStatuses[].image')
if [[ $images =~ $want ]]; then
echo "$want found."
info "$want found."
break
fi

Expand All @@ -271,10 +280,10 @@ function getHelmRevision() {
while true; do
get=$(helm status -n ${namespace} ${releaseName} -o json | jq '.version')
if [[ $get == $wantRevision ]]; then
echo "${releaseName} revision:${wantRevision} found."
info "${releaseName} revision:${wantRevision} found."
break
fi
echo "${releaseName} revision:${get} found.but want:${wantRevision}"
info "${releaseName} revision:${get} found.but want:${wantRevision}"

CURRENT_TIME=$(date +%s)
ELAPSED_TIME=$((CURRENT_TIME - START_TIME))
Expand All @@ -295,7 +304,7 @@ function getDeployReplicas() {
while true; do
images=$(kubectl -n${namespace} get deploy ${deployName} --ignore-not-found=true -o json | jq -r '.spec.replicas')
if [[ $images == $want ]]; then
echo "replicas $want found."
info "replicas:$want found."
break
fi

Expand All @@ -318,14 +327,14 @@ function validateComponentPlanStatusLatestValue() {
while true; do
latestValue=$(kubectl -n${namespace} get ComponentPlan ${componentPlanName} --ignore-not-found=true -ojson | jq -r '.status.latest')
if [[ $latestValue == $want ]]; then
echo "componentPlan ${componentPlanName} status.latest is $latestValue"
info "componentPlan ${componentPlanName} status.latest is $latestValue"
break
fi

CURRENT_TIME=$(date +%s)
ELAPSED_TIME=$((CURRENT_TIME - START_TIME))
if [ $ELAPSED_TIME -gt $TimeoutSeconds ]; then
echo "Timeout reached. componentPlan ${componentPlanName} status.latest is $latestValue, not $want"
echo "Timeout reached. componentPlan:${componentPlanName} status.latest is $latestValue, not $want"
kubectl -n${namespace} get ComponentPlan ${componentPlanName} -o yaml
exit 1
fi
Expand All @@ -341,7 +350,7 @@ function waitComponentPlanRetryTime() {
while true; do
anno=$(kubectl -n${namespace} get ComponentPlan ${componentPlanName} --ignore-not-found=true -ojson | jq -r '.metadata.annotations["core.kubebb.k8s.com.cn/componentplan-retry"]')
if [[ $anno == $retryTimeWant ]]; then
echo "componentPlan ${componentPlanName} retry time match"
info "componentPlan:${componentPlanName} retry time match"
break
fi

Expand Down Expand Up @@ -401,7 +410,7 @@ info "2.2 deploy kubebb/core"
docker tag kubebb/core:latest kubebb/core:example-e2e
kind load docker-image kubebb/core:example-e2e --name=$KindName
make deploy IMG="kubebb/core:example-e2e"
kubectl wait deploy -n kubebb-system kubebb-controller-manager --for condition=Available=True
kubectl wait deploy -n kubebb-system kubebb-controller-manager --for condition=Available=True --timeout=$Timeout

info "3 try to verify that the common steps are valid"
info "3.1 create bitnami repository"
Expand Down
12 changes: 6 additions & 6 deletions controllers/component_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,6 @@ func (r *ComponentReconciler) UpdateValuesConfigmap(ctx context.Context, logger
BearerToken: &cfg.BearerToken,
Namespace: &component.Namespace,
}
h, err := helm.NewHelmWrapper(getter, component.Namespace, logger)
if err != nil {
return err
}
g := new(errgroup.Group)
workers, err := env.GetInt("OCI_PULL_WORKER", 5) // Increase this number will download faster, but also more likely to trigger '429 Too Many Requests' error.
if err != nil {
Expand Down Expand Up @@ -240,7 +236,11 @@ func (r *ComponentReconciler) UpdateValuesConfigmap(ctx context.Context, logger
}
}

dir, entryName, err := h.Pull(ctx, logger, r.Client, repo, pullURL, versionStr)
h, err := helm.NewCoreHelmWrapper(getter, component.Namespace, logger, r.Client, nil, repo, component)
if err != nil {
return err
}
_, dir, entryName, err := h.Pull(ctx, pullURL, versionStr)
if err != nil {
return err
}
Expand All @@ -250,7 +250,7 @@ func (r *ComponentReconciler) UpdateValuesConfigmap(ctx context.Context, logger
return err
}
cm.Data[corev1alpha1.ValuesConfigMapKey] = string(b)
rel, err := h.Template(ctx, logger, r.Client, component, repo, versionStr, dir+"/"+entryName)
rel, err := h.Template(ctx, versionStr, dir+"/"+entryName)
if err != nil {
return err
}
Expand Down
170 changes: 0 additions & 170 deletions pkg/helm/cmd.go

This file was deleted.

Loading

0 comments on commit a4264f6

Please sign in to comment.