generated from kyma-project/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* move (and adjust) tests/operator from serverless * Adjust CRUD operator tests * Add CRUD test to github action * Add more logs for integration tests * Adjust operator-verify * Fix typo in operator-verify * fix operator kustomization config * remove detailed tests message * cleanup --------- Co-authored-by: MichalKalke <[email protected]> Co-authored-by: Michał Kalke <[email protected]>
- Loading branch information
1 parent
57d31b1
commit ecd1db4
Showing
18 changed files
with
505 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
PROJECT_ROOT = ../.. | ||
include ${PROJECT_ROOT}/hack/help.mk | ||
|
||
.PHONY: test | ||
test: ## Run integration test. | ||
go run main.go | ||
|
||
.PHONY: cluster-info | ||
cluster-info: ## Print useful info about the cluster regarding integration run | ||
@echo "####################### Operator Logs #######################" | ||
@kubectl logs -n kyma-system -l app.kubernetes.io/component=dockerregistry-operator.kyma-project.io --tail=-1 || true | ||
@echo "" | ||
|
||
@echo "####################### DockerRegistry CR #######################" | ||
@kubectl get dockerregistry -A -oyaml || true | ||
@echo "" | ||
|
||
@echo "####################### Pods #######################" | ||
@kubectl get pods -A || true | ||
@echo "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package dockerregistry | ||
|
||
import ( | ||
"github.com/kyma-project/docker-registry/components/operator/api/v1alpha1" | ||
"github.com/kyma-project/docker-registry/tests/operator/utils" | ||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func Create(utils *utils.TestUtils) error { | ||
dockerRegistryObj := fixDockerRegistry(utils) | ||
|
||
return utils.Client.Create(utils.Ctx, dockerRegistryObj) | ||
} | ||
|
||
func fixDockerRegistry(testUtils *utils.TestUtils) *v1alpha1.DockerRegistry { | ||
return &v1alpha1.DockerRegistry{ | ||
ObjectMeta: v1.ObjectMeta{ | ||
Name: testUtils.Name, | ||
Namespace: testUtils.Namespace, | ||
}, | ||
Spec: v1alpha1.DockerRegistrySpec{}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package dockerregistry | ||
|
||
import "github.com/kyma-project/docker-registry/tests/operator/utils" | ||
|
||
func Delete(utils *utils.TestUtils) error { | ||
dockerRegistry := fixDockerRegistry(utils) | ||
|
||
return utils.Client.Delete(utils.Ctx, dockerRegistry) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package deployment | ||
|
||
import ( | ||
"fmt" | ||
"github.com/kyma-project/docker-registry/tests/operator/utils" | ||
appsv1 "k8s.io/api/apps/v1" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
func VerifyDockerregistryDeployment(testutils *utils.TestUtils) error { | ||
var deploy appsv1.Deployment | ||
objectKey := client.ObjectKey{ | ||
Name: testutils.DockerregistryDeployName, | ||
Namespace: testutils.Namespace, | ||
} | ||
|
||
err := testutils.Client.Get(testutils.Ctx, objectKey, &deploy) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return verifyDeployReadiness(&deploy) | ||
} | ||
|
||
func verifyDeployReadiness(deploy *appsv1.Deployment) error { | ||
if deploy.Status.Replicas != 0 && deploy.Status.Replicas == deploy.Status.ReadyReplicas { | ||
return nil | ||
} | ||
|
||
return fmt.Errorf("dockerregistry replicas ready '%d' in total '%d'", deploy.Status.ReadyReplicas, deploy.Status.Replicas) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package dockerregistry | ||
|
||
import ( | ||
"github.com/kyma-project/docker-registry/components/operator/api/v1alpha1" | ||
"github.com/kyma-project/docker-registry/tests/operator/utils" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
func Update(testutils *utils.TestUtils) error { | ||
var dockerregistry v1alpha1.DockerRegistry | ||
objectKey := client.ObjectKey{ | ||
Name: testutils.Name, | ||
Namespace: testutils.Namespace, | ||
} | ||
|
||
if err := testutils.Client.Get(testutils.Ctx, objectKey, &dockerregistry); err != nil { | ||
return err | ||
} | ||
|
||
dockerregistry.Spec = testutils.UpdateSpec | ||
|
||
return testutils.Client.Update(testutils.Ctx, &dockerregistry) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package dockerregistry | ||
|
||
import ( | ||
"fmt" | ||
"github.com/kyma-project/docker-registry/components/operator/api/v1alpha1" | ||
"github.com/kyma-project/docker-registry/tests/operator/dockerregistry/deployment" | ||
"github.com/kyma-project/docker-registry/tests/operator/utils" | ||
"k8s.io/apimachinery/pkg/api/errors" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
func VerifyDeletion(utils *utils.TestUtils) error { | ||
err := Verify(utils) | ||
if !errors.IsNotFound(err) { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func Verify(utils *utils.TestUtils) error { | ||
var dockerRegistry v1alpha1.DockerRegistry | ||
objectKey := client.ObjectKey{ | ||
Name: utils.Name, | ||
Namespace: utils.Namespace, | ||
} | ||
|
||
if err := utils.Client.Get(utils.Ctx, objectKey, &dockerRegistry); err != nil { | ||
return err | ||
} | ||
|
||
if err := verifyState(utils, &dockerRegistry); err != nil { | ||
return err | ||
} | ||
|
||
if err := deployment.VerifyDockerregistryDeployment(utils); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func verifyState(utils *utils.TestUtils, dockerRegistry *v1alpha1.DockerRegistry) error { | ||
if dockerRegistry.Status.State != v1alpha1.StateReady { | ||
return fmt.Errorf("dockerregistry '%s' in '%s' state", utils.Name, dockerRegistry.Status.State) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package logger | ||
|
||
import ( | ||
"go.uber.org/zap" | ||
"go.uber.org/zap/zapcore" | ||
) | ||
|
||
func New() (*zap.SugaredLogger, error) { | ||
config := zap.NewDevelopmentConfig() | ||
config.EncoderConfig.TimeKey = "timestamp" | ||
config.Encoding = "json" | ||
config.EncoderConfig.EncodeTime = zapcore.TimeEncoderOfLayout("Jan 02 15:04:05.000000000") | ||
|
||
logger, err := config.Build() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return logger.Sugar(), nil | ||
} |
Oops, something went wrong.