Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Watching for Kyma Custom Resource #7

Merged
merged 32 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
a96042e
Watching resource Kyma CR, temp image name
mvshao May 5, 2023
513f358
First version of event filters
mvshao May 8, 2023
a8fcabb
Working watching Kubeconfig field
mvshao May 9, 2023
bc05c0b
Prepare to present two types of watching resources
mvshao May 10, 2023
28c5a68
Fix invalid format in fmt.Sprintf
mvshao May 10, 2023
2d328d5
Code cleanup
mvshao May 10, 2023
5422866
First round of unit tests for controller
mvshao May 15, 2023
3cdb836
Working test cluster, need to implement tests
mvshao May 15, 2023
1eefe3a
Envtests for reconcilation loop
mvshao May 19, 2023
d886495
Fix Makefile
mvshao May 19, 2023
c8669ad
Fix linting errors
mvshao May 22, 2023
b2b479e
Change the default Docker image path
mvshao May 22, 2023
bf79026
Fix imports
mvshao May 22, 2023
bb97a69
Labeling Kyma CR with compass-id
mvshao May 29, 2023
8196d8c
Skip reconcilation if not signicifant filed in CR is chaned
mvshao May 29, 2023
ace9b9a
Pass the custom interface
mvshao May 29, 2023
f0f3c0a
Provide tests for reconcilation loop
mvshao May 30, 2023
0ecc24c
Resolve vulnerability CVE-2023-2253
mvshao May 30, 2023
072ab87
Fix major lint errors
mvshao May 31, 2023
9e5b6bf
Implement BDD Ginkgo tests
mvshao Jun 1, 2023
eab88b4
Fix Sprintf error
mvshao Jun 1, 2023
7fa9906
Proposed refactoring in the controller.
akgalwas Jun 6, 2023
ffdc016
Proposed refactoring in the controller.
akgalwas Jun 6, 2023
84f7ab2
Fix ginkgo tests
mvshao Jun 7, 2023
2d56740
Deterministic env tests
mvshao Jun 12, 2023
f23343f
Reconciler returns errror with requeue
mvshao Jun 12, 2023
947a45a
Proposed refactoring in the controller's tests.
akgalwas Jun 16, 2023
e901238
Ginkgo test refactor and cleanup
mvshao Jun 20, 2023
e7919c3
Describe table for test cases
mvshao Jun 20, 2023
d244c4d
Remove compassManager CRD
mvshao Jun 20, 2023
b436cad
Cleanup in test and in CRD's
mvshao Jun 20, 2023
623034c
Proposal for simplify predicate passing
mvshao Jun 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o ma
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot
WORKDIR /
COPY --from=builder /workspace/manager .
COPY --chown=65532:65532 --from=builder /workspace/manager .
USER 65532:65532

ENTRYPOINT ["/manager"]
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ vet: ## Run go vet against code.
.PHONY: test
test: manifests generate fmt vet envtest ## Run tests.
ifdef COVERFILE
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -v -coverprofile cover.out
else
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -cover
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -v -cover
endif

##@ Build
Expand Down
12 changes: 11 additions & 1 deletion PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@
# This file is used to track the info used to scaffold your project
# and allow the plugins properly work.
# More info: https://book.kubebuilder.io/reference/project-config.html
domain: compass-manager.kyma-project.io
domain: kyma-project.io
layout:
- go.kubebuilder.io/v3
projectName: compass-manager
repo: github.com/kyma-project/compass-manager
resources:
- api:
crdVersion: v1
namespaced: true
controller: true
domain: kyma-project.io
group: operator
kind: CompassManager
path: github.com/kyma-project/compass-manager/api/v1beta1
version: v1beta1
version: "3"
Empty file removed api/.gitkeep
Empty file.
48 changes: 48 additions & 0 deletions api/v1beta1/compassmanager_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package v1beta1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compass Manager doesn't need to define its own CRD.


import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// CompassManagerSpec defines the desired state of CompassManager
type CompassManagerSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

// Foo is an example field of CompassManager. Edit compassmanager_types.go to remove/update
Foo string `json:"foo,omitempty"`
}

// CompassManagerStatus defines the observed state of CompassManager
type CompassManagerStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// CompassManager is the Schema for the compassmanagers API
type CompassManager struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec CompassManagerSpec `json:"spec,omitempty"`
Status CompassManagerStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// CompassManagerList contains a list of CompassManager
type CompassManagerList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []CompassManager `json:"items"`
}

func init() {
SchemeBuilder.Register(&CompassManager{}, &CompassManagerList{})
}
20 changes: 20 additions & 0 deletions api/v1beta1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Package v1beta1 contains API Schema definitions for the operator v1beta1 API group
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed, as Compass Manager doesn't need have its own CRD.

// +kubebuilder:object:generate=true
// +groupName=operator.kyma-project.io
package v1beta1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "operator.kyma-project.io", Version: "v1beta1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
)
99 changes: 99 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

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

50 changes: 50 additions & 0 deletions config/crd/bases/operator.kyma-project.io_compassmanagers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed, as Compass Manager doesn't need have its own CRD.

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.11.1
creationTimestamp: null
name: compassmanagers.operator.kyma-project.io
spec:
group: operator.kyma-project.io
names:
kind: CompassManager
listKind: CompassManagerList
plural: compassmanagers
singular: compassmanager
scope: Namespaced
versions:
- name: v1beta1
schema:
openAPIV3Schema:
description: CompassManager is the Schema for the compassmanagers API
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: CompassManagerSpec defines the desired state of CompassManager
properties:
foo:
description: Foo is an example field of CompassManager. Edit compassmanager_types.go
to remove/update
type: string
type: object
status:
description: CompassManagerStatus defines the observed state of CompassManager
type: object
type: object
served: true
storage: true
subresources:
status: {}
21 changes: 21 additions & 0 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This kustomization.yaml is not intended to be run by itself,
# since it depends on service name and namespace that are out of this kustomize package.
# It should be run by config/default
resources:
- bases/operator.kyma-project.io_compassmanagers.yaml
#+kubebuilder:scaffold:crdkustomizeresource

patchesStrategicMerge:
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix.
# patches here are for enabling the conversion webhook for each CRD
#- patches/webhook_in_compassmanagers.yaml
#+kubebuilder:scaffold:crdkustomizewebhookpatch

# [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix.
# patches here are for enabling the CA injection for each CRD
#- patches/cainjection_in_compassmanagers.yaml
#+kubebuilder:scaffold:crdkustomizecainjectionpatch

# the following config is for teaching kustomize how to do kustomization for CRDs.
configurations:
- kustomizeconfig.yaml
19 changes: 19 additions & 0 deletions config/crd/kustomizeconfig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This file is for teaching kustomize how to substitute name and namespace reference in CRD
nameReference:
- kind: Service
version: v1
fieldSpecs:
- kind: CustomResourceDefinition
version: v1
group: apiextensions.k8s.io
path: spec/conversion/webhook/clientConfig/service/name

namespace:
- kind: CustomResourceDefinition
version: v1
group: apiextensions.k8s.io
path: spec/conversion/webhook/clientConfig/service/namespace
create: false

varReference:
- path: metadata/annotations
7 changes: 7 additions & 0 deletions config/crd/patches/cainjection_in_compassmanagers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# The following patch adds a directive for certmanager to inject CA into the CRD
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
name: compassmanagers.operator.kyma-project.io
16 changes: 16 additions & 0 deletions config/crd/patches/webhook_in_compassmanagers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# The following patch enables a conversion webhook for the CRD
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it needed? I think not, as Compass Manager doesn't need have its own CRD.

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: compassmanagers.operator.kyma-project.io
spec:
conversion:
strategy: Webhook
webhook:
clientConfig:
service:
namespace: system
name: webhook-service
path: /convert
conversionReviewVersions:
- v1
Loading