mirror of
https://github.com/clastix/kamaji.git
synced 2026-04-15 06:56:47 +00:00
For AddOns and KubeadmPhase the last revision reference has been removed in favor of the md5 hash: this has been required since some information required for the comparison is not persisted in the admin cluster. With this change, the CRD definition has changed too, making this change breaking, although still in v1alpha1.
69 lines
1.8 KiB
Go
69 lines
1.8 KiB
Go
// Copyright 2022 Clastix Labs
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package resources
|
|
|
|
import (
|
|
"math/rand"
|
|
"time"
|
|
|
|
v1 "k8s.io/api/core/v1"
|
|
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
|
|
|
|
kamajiv1alpha1 "github.com/clastix/kamaji/api/v1alpha1"
|
|
)
|
|
|
|
var letters = []byte("abcdefghijklmnopqrstuvwxyz")
|
|
|
|
func updateOperationResult(current controllerutil.OperationResult, op controllerutil.OperationResult) controllerutil.OperationResult {
|
|
if current == controllerutil.OperationResultCreated || op == controllerutil.OperationResultCreated {
|
|
return controllerutil.OperationResultCreated
|
|
}
|
|
|
|
if current == controllerutil.OperationResultUpdated || op == controllerutil.OperationResultUpdated {
|
|
return controllerutil.OperationResultUpdated
|
|
}
|
|
|
|
if current == controllerutil.OperationResultUpdatedStatus || op == controllerutil.OperationResultUpdatedStatus {
|
|
return controllerutil.OperationResultUpdatedStatus
|
|
}
|
|
|
|
if current == controllerutil.OperationResultUpdatedStatusOnly || op == controllerutil.OperationResultUpdatedStatusOnly {
|
|
return controllerutil.OperationResultUpdatedStatusOnly
|
|
}
|
|
|
|
return controllerutil.OperationResultNone
|
|
}
|
|
|
|
func secretProjection(secretName, certKeyName, keyName string) *v1.SecretProjection {
|
|
return &v1.SecretProjection{
|
|
LocalObjectReference: v1.LocalObjectReference{
|
|
Name: secretName,
|
|
},
|
|
Items: []v1.KeyToPath{
|
|
{
|
|
Key: certKeyName,
|
|
Path: certKeyName,
|
|
},
|
|
{
|
|
Key: keyName,
|
|
Path: keyName,
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
func randomString(n int) string {
|
|
rand.Seed(time.Now().UnixNano())
|
|
b := make([]byte, n)
|
|
for i := range b {
|
|
b[i] = letters[rand.Intn(len(letters))]
|
|
}
|
|
|
|
return string(b)
|
|
}
|
|
|
|
func getLatestConfigRV(tenantControlPlane kamajiv1alpha1.TenantControlPlane) string {
|
|
return tenantControlPlane.Status.KubeadmConfig.Checksum
|
|
}
|