Skip to content

Commit

Permalink
Fix missing new fields in AppDefs during KKP upgrades (#13177)
Browse files Browse the repository at this point in the history
* temp: fix missing appdef fields durig installation

Signed-off-by: Simon Bein <simontheleg@gmail.com>

* use existing logic to determine when a deployment has rolled out

---------

Signed-off-by: Simon Bein <simontheleg@gmail.com>
Co-authored-by: Christoph Mewes <christoph@kubermatic.com>
  • Loading branch information
SimonTheLeg and xrstf committed Mar 14, 2024
1 parent db54555 commit d529549
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
17 changes: 17 additions & 0 deletions pkg/ee/default-application-catalog/application_catalog.go
Expand Up @@ -26,14 +26,20 @@ import (
"context"
"fmt"
"io"
"time"

"github.com/sirupsen/logrus"

appskubermaticv1 "k8c.io/kubermatic/v2/pkg/apis/apps.kubermatic/v1"
"k8c.io/kubermatic/v2/pkg/controller/operator/common"
"k8c.io/kubermatic/v2/pkg/install/stack"
"k8c.io/kubermatic/v2/pkg/install/util"
"k8c.io/kubermatic/v2/pkg/log"
"k8c.io/kubermatic/v2/pkg/resources"
kkpreconciling "k8c.io/kubermatic/v2/pkg/resources/reconciling"

appsv1 "k8s.io/api/apps/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
ctrlruntimeclient "sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/yaml"
)
Expand All @@ -52,6 +58,17 @@ func DeployDefaultApplicationCatalog(ctx context.Context, logger *logrus.Entry,
return fmt.Errorf("failed to fetch ApplicationDefinitions: %w", err)
}

sublogger.Info("Waiting for KKP webhook to become ready…")
webhook := &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: common.WebhookDeploymentName,
Namespace: resources.KubermaticNamespace,
},
}
if err := util.WaitForDeploymentRollout(ctx, kubeClient, webhook, opt.Versions.Kubermatic, 5*time.Minute); err != nil {
return fmt.Errorf("failed waiting for webhook: %w", err)
}

creators := []kkpreconciling.NamedApplicationDefinitionReconcilerFactory{}
for _, file := range appDefFiles {
b, err := io.ReadAll(file)
Expand Down
51 changes: 51 additions & 0 deletions pkg/install/util/deployment.go
@@ -0,0 +1,51 @@
/*
Copyright 2024 The Kubermatic Kubernetes Platform contributors.
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 util

import (
"context"
"time"

"k8c.io/kubermatic/v2/pkg/kubernetes"
"k8c.io/kubermatic/v2/pkg/resources"

appsv1 "k8s.io/api/apps/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/util/wait"
ctrlruntimeclient "sigs.k8s.io/controller-runtime/pkg/client"
)

// WaitForDeploymentRollout queries k8s until a deployment with the supplied version exists and
// has been rolled out, or until the timeout is reached.
func WaitForDeploymentRollout(ctx context.Context, client ctrlruntimeclient.Client, deployment *appsv1.Deployment, version string, timeout time.Duration) error {
return wait.PollUntilContextTimeout(ctx, 1*time.Second, timeout, true, func(ctx context.Context) (bool, error) {
dep := &appsv1.Deployment{}
if err := client.Get(ctx, ctrlruntimeclient.ObjectKeyFromObject(deployment), dep); err != nil {
if apierrors.IsNotFound(err) {
return false, nil
}

return false, err
}

if dep.Labels[resources.VersionLabel] != version {
return false, nil
}

return kubernetes.IsDeploymentRolloutComplete(dep, 0)
})
}

0 comments on commit d529549

Please sign in to comment.