-
Notifications
You must be signed in to change notification settings - Fork 996
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
Changes from all commits
11efe23
b25b712
15edc82
9581c78
560cda8
aaabf4e
879de5b
e999846
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
- package: k8s.io/apiextensions-apiserver | ||
version: kubernetes-1.11.1 | ||
version: kubernetes-1.11.3-beta.0 | ||
- package: k8s.io/client-go | ||
version: ^8.0.0 | ||
version: kubernetes-1.11.3-beta.0 | ||
- package: k8s.io/code-generator | ||
version: kubernetes-1.11.1 | ||
version: kubernetes-1.11.3-beta.0 | ||
- package: k8s.io/gengo | ||
- package: gopkg.in/yaml.v2 | ||
- package: github.com/mohae/deepcopy |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
Copyright YEAR Compose, Zalando SE | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
*/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/bash | ||
|
||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
|
||
SCRIPT_ROOT=$(dirname ${BASH_SOURCE})/.. | ||
CODEGEN_PKG=${CODEGEN_PKG:-$(cd ${SCRIPT_ROOT}; ls -d -1 ./vendor/k8s.io/code-generator 2>/dev/null || echo ${GOPATH}/src/k8s.io/code-generator)} | ||
|
||
vendor/k8s.io/code-generator/generate-groups.sh all \ | ||
github.com/zalando-incubator/postgres-operator/pkg/generated github.com/zalando-incubator/postgres-operator/pkg/apis \ | ||
acid.zalan.do:v1 \ | ||
--go-header-file ${SCRIPT_ROOT}/hack/custom-boilerplate.go.txt |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/bin/bash | ||
|
||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
|
||
SCRIPT_ROOT=$(dirname "${BASH_SOURCE}")/.. | ||
DIFFROOT="${SCRIPT_ROOT}/pkg" | ||
TMP_DIFFROOT="${SCRIPT_ROOT}/_tmp/pkg" | ||
_tmp="${SCRIPT_ROOT}/_tmp" | ||
|
||
cleanup() { | ||
rm -rf "${_tmp}" | ||
} | ||
trap "cleanup" EXIT SIGINT | ||
|
||
cleanup | ||
|
||
mkdir -p "${TMP_DIFFROOT}" | ||
cp -a "${DIFFROOT}"/* "${TMP_DIFFROOT}" | ||
|
||
"${SCRIPT_ROOT}/hack/update-codegen.sh" | ||
echo "diffing ${DIFFROOT} against freshly generated codegen" | ||
ret=0 | ||
diff -Naupr "${DIFFROOT}" "${TMP_DIFFROOT}" || ret=$? | ||
cp -a "${TMP_DIFFROOT}"/* "${DIFFROOT}" | ||
if [[ $ret -eq 0 ]] | ||
then | ||
echo "${DIFFROOT} up to date." | ||
else | ||
echo "${DIFFROOT} is out of date. Please run hack/update-codegen.sh" | ||
exit 1 | ||
fi |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package acidzalando | ||
|
||
const ( | ||
// GroupName is the group name for the operator CRDs | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is API group name implied here ? |
||
GroupName = "acid.zalan.do" | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package v1 | ||
|
||
const ( | ||
serviceNameMaxLength = 63 | ||
clusterNameMaxLength = serviceNameMaxLength - len("-repl") | ||
serviceNameRegexString = `^[a-z]([-a-z0-9]*[a-z0-9])?$` | ||
|
||
ClusterStatusUnknown PostgresStatus = "" | ||
ClusterStatusCreating PostgresStatus = "Creating" | ||
ClusterStatusUpdating PostgresStatus = "Updating" | ||
ClusterStatusUpdateFailed PostgresStatus = "UpdateFailed" | ||
ClusterStatusSyncFailed PostgresStatus = "SyncFailed" | ||
ClusterStatusAddFailed PostgresStatus = "CreateFailed" | ||
ClusterStatusRunning PostgresStatus = "Running" | ||
ClusterStatusInvalid PostgresStatus = "Invalid" | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// +k8s:deepcopy-gen=package,register | ||
|
||
// Package v1 is the v1 version of the API. | ||
// +groupName=acid.zalan.do | ||
|
||
package v1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
package v1 | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"strings" | ||
"time" | ||
) | ||
|
||
type postgresqlCopy Postgresql | ||
|
||
// MarshalJSON converts a maintenance window definition to JSON. | ||
func (m *MaintenanceWindow) MarshalJSON() ([]byte, error) { | ||
if m.Everyday { | ||
return []byte(fmt.Sprintf("\"%s-%s\"", | ||
m.StartTime.Format("15:04"), | ||
m.EndTime.Format("15:04"))), nil | ||
} | ||
|
||
return []byte(fmt.Sprintf("\"%s:%s-%s\"", | ||
m.Weekday.String()[:3], | ||
m.StartTime.Format("15:04"), | ||
m.EndTime.Format("15:04"))), nil | ||
} | ||
|
||
// UnmarshalJSON converts a JSON to the maintenance window definition. | ||
func (m *MaintenanceWindow) UnmarshalJSON(data []byte) error { | ||
var ( | ||
got MaintenanceWindow | ||
err error | ||
) | ||
|
||
parts := strings.Split(string(data[1:len(data)-1]), "-") | ||
if len(parts) != 2 { | ||
return fmt.Errorf("incorrect maintenance window format") | ||
} | ||
|
||
fromParts := strings.Split(parts[0], ":") | ||
switch len(fromParts) { | ||
case 3: | ||
got.Everyday = false | ||
got.Weekday, err = parseWeekday(fromParts[0]) | ||
if err != nil { | ||
return fmt.Errorf("could not parse weekday: %v", err) | ||
} | ||
|
||
got.StartTime, err = parseTime(fromParts[1] + ":" + fromParts[2]) | ||
case 2: | ||
got.Everyday = true | ||
got.StartTime, err = parseTime(fromParts[0] + ":" + fromParts[1]) | ||
default: | ||
return fmt.Errorf("incorrect maintenance window format") | ||
} | ||
if err != nil { | ||
return fmt.Errorf("could not parse start time: %v", err) | ||
} | ||
|
||
got.EndTime, err = parseTime(parts[1]) | ||
if err != nil { | ||
return fmt.Errorf("could not parse end time: %v", err) | ||
} | ||
|
||
if got.EndTime.Before(&got.StartTime) { | ||
return fmt.Errorf("'From' time must be prior to the 'To' time") | ||
} | ||
|
||
*m = got | ||
|
||
return nil | ||
} | ||
|
||
// UnmarshalJSON converts a JSON into the PostgreSQL object. | ||
func (p *Postgresql) UnmarshalJSON(data []byte) error { | ||
var tmp postgresqlCopy | ||
|
||
err := json.Unmarshal(data, &tmp) | ||
if err != nil { | ||
metaErr := json.Unmarshal(data, &tmp.ObjectMeta) | ||
if metaErr != nil { | ||
return err | ||
} | ||
|
||
tmp.Error = err.Error() | ||
tmp.Status = ClusterStatusInvalid | ||
|
||
*p = Postgresql(tmp) | ||
|
||
return nil | ||
} | ||
tmp2 := Postgresql(tmp) | ||
|
||
if clusterName, err := extractClusterName(tmp2.ObjectMeta.Name, tmp2.Spec.TeamID); err != nil { | ||
tmp2.Error = err.Error() | ||
tmp2.Status = ClusterStatusInvalid | ||
} else if err := validateCloneClusterDescription(&tmp2.Spec.Clone); err != nil { | ||
tmp2.Error = err.Error() | ||
tmp2.Status = ClusterStatusInvalid | ||
} else { | ||
tmp2.Spec.ClusterName = clusterName | ||
} | ||
|
||
*p = tmp2 | ||
|
||
return nil | ||
} | ||
|
||
func (d *Duration) UnmarshalJSON(b []byte) error { | ||
var ( | ||
v interface{} | ||
err error | ||
) | ||
if err = json.Unmarshal(b, &v); err != nil { | ||
return err | ||
} | ||
switch val := v.(type) { | ||
case string: | ||
t, err := time.ParseDuration(val) | ||
if err != nil { | ||
return err | ||
} | ||
*d = Duration(t) | ||
return nil | ||
case float64: | ||
t := time.Duration(val) | ||
*d = Duration(t) | ||
return nil | ||
default: | ||
return fmt.Errorf("could not recognize type %T as a valid type to unmarshal to Duration", val) | ||
} | ||
} |
There was a problem hiding this comment.
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.