Keda podspec (#2021)
* Add podspec to MQT Signed-off-by: Harsh Thakur <harshthakur9030@gmail.com> * Add preupgrade check Signed-off-by: Harsh Thakur <harshthakur9030@gmail.com> * Use zap logger Signed-off-by: Harsh Thakur <harshthakur9030@gmail.com> Co-authored-by: Sanket Sudake <sanketsudake@gmail.com>
This commit is contained in:
co-authored by
Sanket Sudake
parent
4ff204a0c4
commit
4e2632e100
@@ -48,6 +48,7 @@ type (
|
||||
const (
|
||||
maxRetries = 5
|
||||
FunctionCRD = "functions.fission.io"
|
||||
MqtCRD = "messagequeuetriggers.fission.io"
|
||||
)
|
||||
|
||||
func makePreUpgradeTaskClient(logger *zap.Logger, fnPodNs, envBuilderNs string) (*PreUpgradeTaskClient, error) {
|
||||
@@ -79,16 +80,36 @@ func (client *PreUpgradeTaskClient) GetFunctionCRD() *v1.CustomResourceDefinitio
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetMqtCRD checks if MQT CRD is present on the cluster and returns it. It returns nil if not found
|
||||
func (client *PreUpgradeTaskClient) GetMqtCRD() *v1.CustomResourceDefinition {
|
||||
crd, err := client.apiExtClient.ApiextensionsV1().CustomResourceDefinitions().Get(context.TODO(), MqtCRD, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
client.logger.Error("Could not find MQT CRD", zap.Error(err))
|
||||
return nil
|
||||
}
|
||||
return crd
|
||||
}
|
||||
|
||||
// LatestSchemaApplied ensures that the end user has applied the latest CRDs generated to the cluster.
|
||||
// For future reference: whenever a new field is added, we need to check for that field's existence in this function
|
||||
func (client *PreUpgradeTaskClient) LatestSchemaApplied() error {
|
||||
client.logger.Info("Checking if user has applied the latest CRDs")
|
||||
crd := client.GetFunctionCRD()
|
||||
if crd == nil {
|
||||
funcCRD := client.GetFunctionCRD()
|
||||
if funcCRD == nil {
|
||||
return errors.New("Could not get the Function CRD")
|
||||
}
|
||||
// Any new field added in Function spec can be checked here provided the substring matches the description in CRD Validation of the field
|
||||
if !strings.Contains(crd.Spec.String(), "RequestsPerPod") || !strings.Contains(crd.Spec.String(), "OnceOnly") {
|
||||
if !strings.Contains(funcCRD.Spec.String(), "RequestsPerPod") || !strings.Contains(funcCRD.Spec.String(), "OnceOnly") {
|
||||
return errors.New("Apply the newer CRDs before upgrading")
|
||||
}
|
||||
|
||||
mqtCRD := client.GetMqtCRD()
|
||||
if mqtCRD == nil {
|
||||
return errors.New("Could not get the MQT CRD")
|
||||
}
|
||||
|
||||
// Any new field added in MQT spec can be checked here provided the substring matches the description in CRD Validation of the field
|
||||
if !strings.Contains(mqtCRD.Spec.String(), "PodSpec") {
|
||||
return errors.New("Apply the newer CRDs before upgrading")
|
||||
}
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user