Skip to content

CLOUDP-82159: Upgrade to operator-sdk v1.4.0 #327

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

Merged
merged 7 commits into from
Feb 17, 2021

Conversation

alyacb
Copy link
Contributor

@alyacb alyacb commented Feb 11, 2021

This change re-scaffolds the operator using the latest version of operator-sdk (v1.4.0)

  • Code refactorings:
    • pkg/apis/mongodb/v1/ -> api/v1/
    • pkg/controller/ -> controllers/
  • CRD refactorings:
    • CRDs were moved to config/, CRs to config/samples
    • The new directory structure has roles in config/rbac/
    • operator.yaml was renamed and placed in config/manager/manager.yaml
    • kustomize is being used everywhere
  • Build refactorings:
    • Added a Makefile. The operator can now be built and deployed locally using:
      make generate manifests docker-build docker-push deploy IMG=localhost:5000/mongodb-kubernetes-operator
      • make manifests generates CRDs
      • make generate generates deepcopy code
      • make docker-build docker-push builds the docker image and pushes it. I modified this directive to generate the Dockerfile using our existing scripts, but if you want to generate a Dockerfile other than the operator, e.g. e2e, you can now run make docker-build docker-push IMG=localhost:5000/e2e DOCKERFILE=e2e
    • Changes to the operator Dockerfile template to build the code in the same way as the Makefile
    • Changes to any affected scripts so they can work with the new directory format/ way of building

It was necessary to remove the wrappers around the StatefulSetConfiguration field in mongodb_types, as fields annotated with "-" json struct tags no longer are included, not even with the custom JSON marshalling code. This reintroduced CRD pollution (and accounts for most of the liens of code changed). The CRD is automatically generated, so hopefully this shouldn't be too much of a problem.

StatefulSetConfiguration appsv1.StatefulSetSpec `json:"statefulSet,omitempty"`

For a similar reason, these changes break the additionalMongodConfig field(the only failing e2e test is e2e_test_replica_set_mongod_config). However, the fix for this field is not apparent, since its type boils down to map[string]interface{}, which cannot be generated in the CRDs as interface{} is not a named type.

Note: this doesn't include the necessary documentation changes, which should be added in a separate PR.

@alyacb alyacb added the wip label Feb 11, 2021
@alyacb alyacb force-pushed the CLOUDP-82159_upgrade_operator_sdk_v1 branch 4 times, most recently from 2ff254a to bef215d Compare February 15, 2021 09:33
@alyacb alyacb force-pushed the CLOUDP-82159_upgrade_operator_sdk_v1 branch from 4eedf29 to 86596b2 Compare February 16, 2021 10:38
@@ -19,17 +19,6 @@ functions:
params:
directory: mongodb-kubernetes-operator

setup_operator_sdk:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No longer needed, so I removed this step.

@@ -69,7 +69,7 @@ type MongoDBCommunitySpec struct {
Users []MongoDBUser `json:"users"`

// +optional
StatefulSetConfiguration StatefulSetConfiguration `json:"statefulSet,omitempty"`
StatefulSetConfiguration appsv1.StatefulSetSpec `json:"statefulSet,omitempty"`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change fixed the statefulset_arbitrary e2e tests. For some reason, even though the custom marshal/unmarshal code should be including this field when annotated with "-", it is being ignored. For that reason I reintroduced the CRD generation (which should be fine as long as we can automatically generate 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.

we need to make sure the end resource still works by specifying statefulSet.spec

@@ -9,4 +9,5 @@ if ! whoami >/dev/null 2>&1; then
fi
fi

exec "${OPERATOR}" "$@"
echo "Running ./${OPERATOR}"
"./${OPERATOR}" "$@"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

exec was not working, so I switched to "./"

@alyacb alyacb force-pushed the CLOUDP-82159_upgrade_operator_sdk_v1 branch from 86596b2 to 5c054bc Compare February 16, 2021 10:53
@alyacb alyacb changed the title [WIP] CLOUDP-82159: Upgrade to operator-sdk v1.4.0 CLOUDP-82159: Upgrade to operator-sdk v1.4.0 Feb 16, 2021
@alyacb alyacb requested a review from chatton February 16, 2021 11:14
Copy link
Contributor

@chatton chatton left a comment

Choose a reason for hiding this comment

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

Looks great, massive work! Had a few comments, the main issue we need to address is fixing the test failures in the additionalMongodConfig test and making sure that the spec of the MongoDBCommunity resources is still mdb.spec.statefulSet.spec.*

@@ -69,7 +69,7 @@ type MongoDBCommunitySpec struct {
Users []MongoDBUser `json:"users"`

// +optional
StatefulSetConfiguration StatefulSetConfiguration `json:"statefulSet,omitempty"`
StatefulSetConfiguration appsv1.StatefulSetSpec `json:"statefulSet,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

we need to make sure the end resource still works by specifying statefulSet.spec


return nil
// SetupWithManager sets up the controller with the Manager and configures the necessary watches.
func (r *ReplicaSetReconciler) SetupWithManager(mgr ctrl.Manager) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

[q] is there a reason this is a method and not a function? Does this implement some interface that is required?

Not a big deal either way!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think it's required, but it is the way the scaffolding intended (and matches the Reconcile method). I don't think this particular method gets called anywhere outside of main.go (e.g. by the library), but my vote would be to keep it consistent with operator-sdk's expectations so that we don't diverge too far, just in case they introduce code expecting it to follow this format.

@alyacb
Copy link
Contributor Author

alyacb commented Feb 16, 2021

Pushed changes to move back to CRD version v1beta1 and address feedback. Note that whenever we are ready to move to version v1beta1, here's what needs to happen:

  1. Replace all occurrences of v1beta1 in the code with v1
  2. Change this line in the Makefile from:
CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=true,crdVersions=v1beta1"

to:

CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false"
  1. Add the following annotation to the StatefulSetConfiguration and AdditionalMongodConfig fields on the MongoDBCommunitySpec struct. This is the v1 replacement for preserveUnknownFields.
// +kubebuilder:validation:XPreserveUnknownFields
  1. Run make generate manifests

@alyacb alyacb removed the wip label Feb 16, 2021
@alyacb alyacb marked this pull request as ready for review February 16, 2021 16:38
Copy link
Contributor

@chatton chatton left a comment

Choose a reason for hiding this comment

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

This looks amazing! I think we're good to go, I think if @bznein / @irajdeep can take a look at this as well that would be great.

We can tackle the upgrade from v1beta1 to v1 in a future PR.

cc @rodrigovalin this will be a great PR to use as a reference when working on the CRD project.

@irajdeep irajdeep self-requested a review February 16, 2021 17:58
Copy link
Contributor

@irajdeep irajdeep left a comment

Choose a reason for hiding this comment

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

LGTM! Great work. Added some minor comments.

@@ -0,0 +1,10 @@
# 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.
Copy link
Contributor

Choose a reason for hiding this comment

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

q: are we adding kustomize support with this PR as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. The project was re-scaffolded with the new version of operator-sdk, which generated a bunch of kustomize files for us. The make deploy target in the Makefile uses kustomize to generate the yaml it applies.

@alyacb alyacb merged commit e7c6368 into master Feb 17, 2021
@alyacb alyacb deleted the CLOUDP-82159_upgrade_operator_sdk_v1 branch February 17, 2021 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants