Skip to content

Commit

Permalink
new custom state check (#784)
Browse files Browse the repository at this point in the history
* add new state check to moduletemplate

* add custom state check logic

* update v1beta1

* update conversion

* test change from CustomStateCheck to StateCheck

* use CustomStateCheck

* fix lint

* fix lint

* put state to warning after certain period if state can't be found

* fix test

* fix test

* fix linter issue
  • Loading branch information
ruanxin authored Aug 17, 2023
1 parent c4f436c commit e76fb55
Show file tree
Hide file tree
Showing 15 changed files with 711 additions and 96 deletions.
1 change: 0 additions & 1 deletion api/v1beta1/moduletemplate_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ func (src *ModuleTemplate) ConvertTo(dstRaw conversion.Hub) error {
dst.Spec.Data = src.Spec.Data
dst.Spec.Descriptor = src.Spec.Descriptor
dst.Spec.CustomStateCheck = src.Spec.CustomStateCheck

return nil
}

Expand Down
3 changes: 1 addition & 2 deletions api/v1beta1/moduletemplate_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ type ModuleTemplateSpec struct {
// hint by downstream controllers to determine which client implementation to use for working with the Module
Target Target `json:"target"`

// CustomStateCheck for advanced Module State determination
CustomStateCheck *v1beta2.CustomStateCheck `json:"customStateCheck,omitempty"`
CustomStateCheck []*v1beta2.CustomStateCheck `json:"customStateCheck,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down
10 changes: 8 additions & 2 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions api/v1beta2/moduletemplate_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,18 @@ type ModuleTemplateSpec struct {
//+kubebuilder:pruning:PreserveUnknownFields
Descriptor runtime.RawExtension `json:"descriptor"`

// CustomStateCheck for advanced Module State determination
CustomStateCheck *CustomStateCheck `json:"customStateCheck,omitempty"`
CustomStateCheck []*CustomStateCheck `json:"customStateCheck,omitempty"`
}

type CustomStateCheck struct {
// JSONPath specifies the JSON path to the state variable in the Module CR
JSONPath string `json:"jsonPath"`

// Value is the value at the JSONPath for which the Module CR state is set to "Ready" in Kyma CR
// Value is the value at the JSONPath for which the Module CR state should map with MappedState
Value string `json:"value"`

// MappedState is the Kyma CR State
MappedState State `json:"mappedState"`
}

func (m *ModuleTemplate) GetDescriptor() (*Descriptor, error) {
Expand Down
9 changes: 5 additions & 4 deletions api/v1beta2/operator_annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ const (
// OwnedByAnnotation defines the resource managing the resource. Differing from ManagedBy
// in that it does not reference controllers. Used by the runtime-watcher to determine the
// corresponding CR in KCP.
OwnedByAnnotation = OperatorPrefix + Separator + "owned-by"
OwnedByFormat = "%s/%s"
SyncStrategyAnnotation = "sync-strategy"
IsClusterScopedAnnotation = OperatorPrefix + Separator + "is-cluster-scoped"
OwnedByAnnotation = OperatorPrefix + Separator + "owned-by"
OwnedByFormat = "%s/%s"
SyncStrategyAnnotation = "sync-strategy"
IsClusterScopedAnnotation = OperatorPrefix + Separator + "is-cluster-scoped"
CustomStateCheckAnnotation = OperatorPrefix + Separator + "custom-state-check"
)
10 changes: 8 additions & 2 deletions api/v1beta2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 52 additions & 28 deletions config/crd/bases/operator.kyma-project.io_moduletemplates.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,32 @@ spec:
pattern: ^[a-z]+$
type: string
customStateCheck:
description: CustomStateCheck for advanced Module State determination
properties:
jsonPath:
description: JSONPath specifies the JSON path to the state variable
in the Module CR
type: string
value:
description: Value is the value at the JSONPath for which the
Module CR state is set to "Ready" in Kyma CR
type: string
required:
- jsonPath
- value
type: object
items:
properties:
jsonPath:
description: JSONPath specifies the JSON path to the state variable
in the Module CR
type: string
mappedState:
description: MappedState is the Kyma CR State
enum:
- Processing
- Deleting
- Ready
- Error
- ""
- Warning
type: string
value:
description: Value is the value at the JSONPath for which the
Module CR state should map with MappedState
type: string
required:
- jsonPath
- mappedState
- value
type: object
type: array
data:
description: Data is the default set of attributes that are used to
generate the Module. It contains a default set of values for a given
Expand Down Expand Up @@ -140,20 +152,32 @@ spec:
pattern: ^[a-z]+$
type: string
customStateCheck:
description: CustomStateCheck for advanced Module State determination
properties:
jsonPath:
description: JSONPath specifies the JSON path to the state variable
in the Module CR
type: string
value:
description: Value is the value at the JSONPath for which the
Module CR state is set to "Ready" in Kyma CR
type: string
required:
- jsonPath
- value
type: object
items:
properties:
jsonPath:
description: JSONPath specifies the JSON path to the state variable
in the Module CR
type: string
mappedState:
description: MappedState is the Kyma CR State
enum:
- Processing
- Deleting
- Ready
- Error
- ""
- Warning
type: string
value:
description: Value is the value at the JSONPath for which the
Module CR state should map with MappedState
type: string
required:
- jsonPath
- mappedState
- value
type: object
type: array
data:
description: Data is the default set of attributes that are used to
generate the Module. It contains a default set of values for a given
Expand Down
14 changes: 0 additions & 14 deletions controllers/manifest_controller/manifest_controller_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import (
"github.com/google/go-containerregistry/pkg/v1/types"
. "github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/rand"
"k8s.io/apimachinery/pkg/util/uuid"
)

const CredSecretLabelKeyForTest = "operator.kyma-project.io/oci-registry-cred" //nolint:gosec
Expand Down Expand Up @@ -94,18 +92,6 @@ func createOCIImageSpec(name, repo string, enableCredSecretSelector bool) v1beta
return imageSpec
}

func NewTestManifest(prefix string) *v1beta2.Manifest {
return &v1beta2.Manifest{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-%d", prefix, rand.Intn(999999)),
Namespace: metav1.NamespaceDefault,
Labels: map[string]string{
v1beta2.KymaName: string(uuid.NewUUID()),
},
},
}
}

func withInvalidInstallImageSpec(enableResource bool) func(manifest *v1beta2.Manifest) error {
return func(manifest *v1beta2.Manifest) error {
invalidImageSpec := createOCIImageSpec("invalid-image-spec", "domain.invalid", false)
Expand Down
5 changes: 3 additions & 2 deletions controllers/manifest_controller/manifest_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/kyma-project/lifecycle-manager/api/v1beta2"
declarative "github.com/kyma-project/lifecycle-manager/internal/declarative/v2"
"github.com/kyma-project/lifecycle-manager/pkg/ocmextensions"
"github.com/kyma-project/lifecycle-manager/pkg/testutils"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
Expand All @@ -35,7 +36,7 @@ var _ = Describe(
givenCondition func(manifest *v1beta2.Manifest) error,
expectManifestState func(manifestName string) error,
) {
manifest := NewTestManifest("oci")
manifest := testutils.NewTestManifest("oci")
Eventually(givenCondition, standardTimeout, standardInterval).
WithArguments(manifest).Should(Succeed())
Eventually(expectManifestState, standardTimeout, standardInterval).
Expand Down Expand Up @@ -81,7 +82,7 @@ var _ = Describe(
)

It("Manifest should be in Error state with no auth secret found error message", func() {
manifestWithInstall := NewTestManifest("private-oci-registry")
manifestWithInstall := testutils.NewTestManifest("private-oci-registry")
Eventually(withValidInstallImageSpec(installName, false, true), standardTimeout, standardInterval).
WithArguments(manifestWithInstall).Should(Succeed())
Eventually(func() string {
Expand Down
3 changes: 2 additions & 1 deletion controllers/manifest_controller/ready_check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

declarative "github.com/kyma-project/lifecycle-manager/internal/declarative/v2"
"github.com/kyma-project/lifecycle-manager/internal/manifest"
"github.com/kyma-project/lifecycle-manager/pkg/testutils"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -33,7 +34,7 @@ var _ = Describe("Manifest readiness check", Ordered, func() {
},
)
It("Install OCI specs including an nginx deployment", func() {
testManifest := NewTestManifest("custom-check-oci")
testManifest := testutils.NewTestManifest("custom-check-oci")
manifestName := testManifest.GetName()
validImageSpec := createOCIImageSpec(installName, server.Listener.Addr().String(), false)
imageSpecByte, err := json.Marshal(validImageSpec)
Expand Down
Loading

0 comments on commit e76fb55

Please sign in to comment.