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

Use code-generation for CRD API and deepcopy methods #369

Merged
merged 8 commits into from
Aug 15, 2018

Conversation

alexeyklyukin
Copy link
Contributor

@alexeyklyukin alexeyklyukin commented Aug 10, 2018

Client-go provides a https://github.com/kubernetes/code-generator package in order to provide the API to work with CRDs similar to the one available for built-in types, i.e. Pods, Statefulsets and so on.

Use this package to generate deepcopy methods (required for CRDs), instead of using an external deepcopy package; we also generate APIs used to manipulate both Postgres and OperatorConfiguration CRDs, as well as informers and listers for the Postgres CRD, instead of using generic informers and CRD REST API; by using generated code we can get rid of some custom and obscure CRD-related code and use a better API.

Right now we only use autogenerated code for deepcopy and only for
the Postgresql and PostgreqlList objects.

Moved Postgresql, PostgresqlList and other types used by them into
the apis/acid.zalan.do/v1 package.

Error field in the CRD has been replaced by a string, since Error
didn't work nicely with the deepcopy-gen.
Remove some of the boilerplate code.  Sovle the issue with PostgreSQL
CRD kind not matching the expectations in the generated code due to the
case difference.
Move generated code to /generated.

Rename postgres-operator-configuration CRD to OperatorConfiguration
for compatibility with generated code.

The only missing bit that requires the old code is updating the status
return metav1.Time{}, err
}

return metav1.Time{tp.UTC()}, nil

Choose a reason for hiding this comment

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

github.com/zalando-incubator/postgres-operator/vendor/k8s.io/apimachinery/pkg/apis/meta/v1.Time composite literal uses unkeyed fields

Right now we set the status with Update, however, Kubernetes 1.11
introduces the /status subresources, allowing us to set the status with
the special updateStatus call in the future. For now, we keep the code
that is compatible with earlier versions of Kubernetes.

As an upside, remove a lot of custom code for building the REST client
for CRDs, as this is now handled by the autogenerated API. We could
remove the custom unmarshaller as well, once we figure out how CRD
validation.

Also renamed postgresql.go to the database go (code that works with
databases, to avoid confusion with the code that deals with PostgreSQL
objects) and status.go to logs_and_api.go to distinguish between the
code that deals with PostgreSQL object status and the one that performs
logging and API utilities.
c.Status = status
b, err := json.Marshal(status)
func (c *Cluster) setStatus(status acidv1.ClusterStateType) {
c.Status = acidv1.PostgresStatus{status}

Choose a reason for hiding this comment

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

github.com/zalando-incubator/postgres-operator/pkg/apis/acid.zalan.do/v1.PostgresStatus composite literal uses unkeyed fields

Need to maintain compatiblity with already running clusters.
In addition, revert to patch for changing the status instead of a
full-scale update, as there is no guarantee the update will supply the
actual resourceVersion.
err error
b []byte
)
b, err = json.Marshal(status)

Choose a reason for hiding this comment

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

ineffectual assignment to err

@coveralls
Copy link

coveralls commented Aug 14, 2018

Coverage Status

Coverage increased (+19.04%) to 23.673% when pulling e999846 on crd_autogeneration into 6e8dcab on master.

Generate only GET verbs and no status.
@alexeyklyukin alexeyklyukin changed the title WIP/CRD generation Use code-generation for CRD API and deepcopy methods Aug 15, 2018
Copy link
Member

@sdudoladov sdudoladov left a comment

Choose a reason for hiding this comment

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

  1. Can you please leave a short comment in the developer docs about the overall code generation idea, benefits, code structure and must-have links to the k8s docs besides other operators ?
  2. Let's say we introduce new parts of the API, say v2. Would it be sufficient to create v2 directory under the API group dir, describe interfaces there with appropriate annotations and then invoke code generation ?

package acidzalando

const (
// GroupName is the group name for the operator CRDs
Copy link
Member

Choose a reason for hiding this comment

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

is API group name implied here ?

Error string `json:"-"`
}

// PostgresSpec defines the specification for the PostgreSQL TPR.
Copy link
Member

Choose a reason for hiding this comment

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

postgresql CRD and not TPR?

@@ -11,13 +11,13 @@ import:
- package: github.com/lib/pq
- package: github.com/motomux/pretty
- package: k8s.io/apimachinery
version: kubernetes-1.11.1
version: kubernetes-1.11.3-beta.0
Copy link
Member

@sdudoladov sdudoladov Aug 15, 2018

Choose a reason for hiding this comment

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

  1. versions have to be specified as precisely as possible , e.g. kubernetes-1.11.3-beta.0 and not ^8.0.0
  2. versions for client-go, code-generator and apimachinery have to match

@alexeyklyukin alexeyklyukin merged commit e1ed4b8 into master Aug 15, 2018
@@ -12,7 +12,7 @@ configuration.

* CRD-based configuration. The configuration is stored in the custom YAML
manifest, an instance of the custom resource definition (CRD) called
`postgresql-operator-configuration`. This CRD is registered by the operator
`OperatorConfiguration`. This CRD is registered by the operator
Copy link
Member

Choose a reason for hiding this comment

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

This renaming was necessary because the older name with dashes broke the code generation process.

@erthalion erthalion deleted the crd_autogeneration branch September 13, 2018 09:16
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.

4 participants