Skip to content

Commit

Permalink
Bring back support for k8s 1.11 (kubedb#481)
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha authored Jan 5, 2020
1 parent 8e913f5 commit 17bd64f
Show file tree
Hide file tree
Showing 42 changed files with 5,175 additions and 3,817 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ jobs:

- name: Run checks
run: |
sudo apt-get -qq update
sudo apt-get -qq update || true
sudo apt-get install -y bzr
make ci
4 changes: 2 additions & 2 deletions api/crds/bindata.go

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions api/crds/kubedb.com_dormantdatabases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ spec:
additionalProperties:
type: string
type: object
creationTimestamp:
format: date-time
type: string
generateName:
type: string
labels:
Expand Down
4 changes: 0 additions & 4 deletions api/openapi-spec/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -27875,10 +27875,6 @@
"type": "string"
}
},
"creationTimestamp": {
"description": "CreationTimestamp is a timestamp representing the server time when this object was created. It is not guaranteed to be set in happens-before order across separate operations. Clients may not set this value. It is represented in RFC3339 form and is in UTC.\n\nPopulated by the system. Read-only. Null for lists. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata",
"$ref": "#/definitions/io.k8s.apimachinery.pkg.apis.meta.v1.Time"
},
"generateName": {
"description": "GenerateName is an optional prefix, used by the server, to generate a unique name ONLY IF the Name field has not been provided. If this field is used, the name returned to the client will be different than the name passed. This value will also be combined with a unique suffix. The provided value has the same validation rules as the Name field, and may be truncated by the length of the suffix required to make the value unique on the server.\n\nIf this field is specified and the generated name exists, the server will NOT return a 409 - instead, it will either return 201 Created or 500 with Reason ServerTimeout indicating a unique name could not be found in the time allotted, and the client should retry (optionally after the time indicated in the Retry-After header).\n\nApplied only if Name is not specified. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#idempotency",
"type": "string"
Expand Down
8 changes: 1 addition & 7 deletions apis/catalog/v1alpha1/openapi_generated.go

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

8 changes: 1 addition & 7 deletions apis/config/v1alpha1/openapi_generated.go

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

8 changes: 1 addition & 7 deletions apis/dba/v1alpha1/openapi_generated.go

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

8 changes: 1 addition & 7 deletions apis/kubedb/v1alpha1/openapi_generated.go

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

8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ require (
k8s.io/apimachinery v0.16.5-beta.1
k8s.io/client-go v12.0.0+incompatible
k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a
kmodules.xyz/client-go v0.0.0-20191219184245-880ab4b0e5db
kmodules.xyz/client-go v0.0.0-20200105092743-4b797c0c0802
kmodules.xyz/crd-schema-fuzz v0.0.0-20191129174258-81f984340891
kmodules.xyz/custom-resources v0.0.0-20191130062942-f41b54f62419
kmodules.xyz/monitoring-agent-api v0.0.0-20191223205013-784042d6a958
kmodules.xyz/monitoring-agent-api v0.0.0-20191224204126-ee69caffab6c
kmodules.xyz/objectstore-api v0.0.0-20191127144749-5881939b57f0
kmodules.xyz/offshoot-api v0.0.0-20191204032627-ee9a85c51ab3
kmodules.xyz/offshoot-api v0.0.0-20200103145223-2c4f520520d2
kmodules.xyz/webhook-runtime v0.0.0-20191127075323-d4bfdee6974d
sigs.k8s.io/yaml v1.1.0
stash.appscode.dev/stash v0.9.0-rc.2.0.20191220142029-ca6885400de1
stash.appscode.dev/stash v0.9.0-rc.2.0.20200104002701-d6e0fe4b9305
)

replace (
Expand Down
17 changes: 9 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -791,20 +791,21 @@ k8s.io/utils v0.0.0-20190801114015-581e00157fb1 h1:+ySTxfHnfzZb9ys375PXNlLhkJPLK
k8s.io/utils v0.0.0-20190801114015-581e00157fb1/go.mod h1:sZAwmy6armz5eXlNoLmJcl4F1QuKu7sr+mFQ0byX7Ew=
kmodules.xyz/client-go v0.0.0-20191127054604-26981530831d/go.mod h1:OFxuKCiVR+MYlR2a08FkfaF+IbXkLe0xBetu2LTUuGI=
kmodules.xyz/client-go v0.0.0-20191211192817-f1dcd02124ba/go.mod h1:OFxuKCiVR+MYlR2a08FkfaF+IbXkLe0xBetu2LTUuGI=
kmodules.xyz/client-go v0.0.0-20191219184245-880ab4b0e5db h1:6ucciOzNh6nKC5uN3DetZ/rLtp/mgc3SfFSFL+sZEX0=
kmodules.xyz/client-go v0.0.0-20191219184245-880ab4b0e5db/go.mod h1:OFxuKCiVR+MYlR2a08FkfaF+IbXkLe0xBetu2LTUuGI=
kmodules.xyz/client-go v0.0.0-20200101081724-6b136a38d486/go.mod h1:OFxuKCiVR+MYlR2a08FkfaF+IbXkLe0xBetu2LTUuGI=
kmodules.xyz/client-go v0.0.0-20200105092743-4b797c0c0802 h1:INQ3RPEcdLX4m7Ql+eTyDjtRYrQlK/D9hrcDuAijw6c=
kmodules.xyz/client-go v0.0.0-20200105092743-4b797c0c0802/go.mod h1:OFxuKCiVR+MYlR2a08FkfaF+IbXkLe0xBetu2LTUuGI=
kmodules.xyz/constants v0.0.0-20191024095500-cd4313df4aa6 h1:hFv3DzanQJ/bjgahqosmthGLkVgMB2KuQIsltOA02t0=
kmodules.xyz/constants v0.0.0-20191024095500-cd4313df4aa6/go.mod h1:DbiFk1bJ1KEO94t1SlAn7tzc+Zz95rSXgyUKa2nzPmY=
kmodules.xyz/crd-schema-fuzz v0.0.0-20191129174258-81f984340891 h1:2W/fqLbAurvupIZL3TEFrlb7DnOIhlOXpNgzgcFFSmA=
kmodules.xyz/crd-schema-fuzz v0.0.0-20191129174258-81f984340891/go.mod h1:9NXNZ4xhqof0WngtIuo4vl+WoCQpLJEJcyuEo3mPpiM=
kmodules.xyz/custom-resources v0.0.0-20191130062942-f41b54f62419 h1:o6KD8XMxdyRR3rqScTsWvcufFDT7vQBnYXpHUp6UtRg=
kmodules.xyz/custom-resources v0.0.0-20191130062942-f41b54f62419/go.mod h1:EksiAQK3p3bVU5cNBjLT0z5V7er1tvWLBWILTuf6G/0=
kmodules.xyz/monitoring-agent-api v0.0.0-20191223205013-784042d6a958 h1:Ctoy2Rx2O3lCfxGBo4cPshopqo/2gJ+oXx/M45GxOEs=
kmodules.xyz/monitoring-agent-api v0.0.0-20191223205013-784042d6a958/go.mod h1:q5Adit2fxEoY1jSkYiK1t856Ombl8cunYJBmgL43wwc=
kmodules.xyz/monitoring-agent-api v0.0.0-20191224204126-ee69caffab6c h1:+FRIAY8BTrTNg+OU0nbrQu2bC4J5rzan7gkiHlqc+Gk=
kmodules.xyz/monitoring-agent-api v0.0.0-20191224204126-ee69caffab6c/go.mod h1:q5Adit2fxEoY1jSkYiK1t856Ombl8cunYJBmgL43wwc=
kmodules.xyz/objectstore-api v0.0.0-20191127144749-5881939b57f0 h1:ilgkGU/bteKRvH99piXxU8b2c1E9lwxb0sDpLLhy4iY=
kmodules.xyz/objectstore-api v0.0.0-20191127144749-5881939b57f0/go.mod h1:AE1rz+T/3dlUwH5pLgCNghWeeFfeVBnBXKJVpsLHlmc=
kmodules.xyz/offshoot-api v0.0.0-20191204032627-ee9a85c51ab3 h1:DW3lX0hZzx14WTNCU+RTWU2eKZ4xbKpUvYVy6S5OtBc=
kmodules.xyz/offshoot-api v0.0.0-20191204032627-ee9a85c51ab3/go.mod h1:k1M+OOFHbMeS6N6OB2j9smKfMCyQOEQjZ3SLZ/KSe+w=
kmodules.xyz/offshoot-api v0.0.0-20200103145223-2c4f520520d2 h1:c/wxNy8KgaS8v/htruqtL0YgrKciUKroK1zXPVZHuqg=
kmodules.xyz/offshoot-api v0.0.0-20200103145223-2c4f520520d2/go.mod h1:k1M+OOFHbMeS6N6OB2j9smKfMCyQOEQjZ3SLZ/KSe+w=
kmodules.xyz/openshift v0.0.0-20191127054841-113eeb13704f/go.mod h1:de9+Zk2+wtGhRmGFBZ9T4+0lJZr4rHXW0dHffCaeO+g=
kmodules.xyz/openshift v0.0.0-20191127145035-f6c48a90dbb7/go.mod h1:de9+Zk2+wtGhRmGFBZ9T4+0lJZr4rHXW0dHffCaeO+g=
kmodules.xyz/prober v0.0.0-20191216013129-7c91e2b0edb2 h1:wxHidC0FZfaHTRG8ADG9qdxTBHXGUJylWEsTV/m/6Rg=
Expand All @@ -826,6 +827,6 @@ sigs.k8s.io/testing_frameworks v0.1.1/go.mod h1:VVBKrHmJ6Ekkfz284YKhQePcdycOzNH9
sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs=
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
software.sslmate.com/src/go-pkcs12 v0.0.0-20180114231543-2291e8f0f237/go.mod h1:/xvNRWUqm0+/ZMiF4EX00vrSCMsE4/NHb+Pt3freEeQ=
stash.appscode.dev/stash v0.9.0-rc.2.0.20191220142029-ca6885400de1 h1:f8U9rRn+HK14rMeACXI4XWPygJYLAvzxvpfXEn3t0G0=
stash.appscode.dev/stash v0.9.0-rc.2.0.20191220142029-ca6885400de1/go.mod h1:XGmFKv77U95iI1P8FHMAiotv615kYLY9dKq14wPUs+M=
stash.appscode.dev/stash v0.9.0-rc.2.0.20200104002701-d6e0fe4b9305 h1:JZD1gyMfIXRzda6Ft3phbVrRexlMZ7gQkXDsrR8AXls=
stash.appscode.dev/stash v0.9.0-rc.2.0.20200104002701-d6e0fe4b9305/go.mod h1:D4GgyrrJt0ZcN9/OImA0f/E6xIaO3cpM5ig2zAbK7rc=
vbom.ml/util v0.0.0-20160121211510-db5cfe13f5cc/go.mod h1:so/NYdZXCz+E3ZpW0uAoCj6uzU2+8OWDFv/HxUSs7kI=
2 changes: 1 addition & 1 deletion pkg/controller/dormantdatabase/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (c *Controller) EnsureCustomResourceDefinitions() error {
crd := []*crd_api.CustomResourceDefinition{
api.DormantDatabase{}.CustomResourceDefinition(),
}
return crdutils.RegisterCRDs(c.ApiExtKubeClient, crd)
return crdutils.RegisterCRDs(c.Client.Discovery(), c.ApiExtKubeClient, crd)
}

func (c *Controller) InitInformer() cache.SharedIndexInformer {
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/snapshot/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (c *Controller) EnsureCustomResourceDefinitions() error {
crd := []*crd_api.CustomResourceDefinition{
api.Snapshot{}.CustomResourceDefinition(),
}
return crdutils.RegisterCRDs(c.ApiExtKubeClient, crd)
return crdutils.RegisterCRDs(c.Client.Discovery(), c.ApiExtKubeClient, crd)
}

// InitInformer ensures snapshot watcher and returns queue.Worker.
Expand Down
24 changes: 19 additions & 5 deletions vendor/kmodules.xyz/client-go/apiextensions/v1beta1/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,34 @@ import (
"net/http"
"time"

discovery_util "kmodules.xyz/client-go/discovery"

"github.com/pkg/errors"
crd_api "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
crd_cs "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/typed/apiextensions/v1beta1"
kerr "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/discovery"
"k8s.io/client-go/rest"
)

func RegisterCRDs(client crd_cs.ApiextensionsV1beta1Interface, crds []*crd_api.CustomResourceDefinition) error {
func RegisterCRDs(disClient discovery.DiscoveryInterface, apiextClient crd_cs.ApiextensionsV1beta1Interface, crds []*crd_api.CustomResourceDefinition) error {
major, minor, _, _, _, err := discovery_util.GetVersionInfo(disClient)
if err != nil {
return err
}

for _, crd := range crds {
existing, err := client.CustomResourceDefinitions().Get(crd.Name, metav1.GetOptions{})
if major == 1 && minor <= 11 {
// CRD schema must only have "properties", "required" or "description" at the root if the status subresource is enabled
// xref: https://github.com/stashed/stash/issues/1007#issuecomment-570888875
crd.Spec.Validation.OpenAPIV3Schema.Type = ""
}

existing, err := apiextClient.CustomResourceDefinitions().Get(crd.Name, metav1.GetOptions{})
if kerr.IsNotFound(err) {
_, err = client.CustomResourceDefinitions().Create(crd)
_, err = apiextClient.CustomResourceDefinitions().Create(crd)
if err != nil {
return err
}
Expand All @@ -43,13 +57,13 @@ func RegisterCRDs(client crd_cs.ApiextensionsV1beta1Interface, crds []*crd_api.C
} else if crd.Spec.Subresources == nil && existing.Spec.Subresources != nil {
existing.Spec.Subresources = nil
}
_, err = client.CustomResourceDefinitions().Update(existing)
_, err = apiextClient.CustomResourceDefinitions().Update(existing)
if err != nil {
return err
}
}
}
return WaitForCRDReady(client.RESTClient(), crds)
return WaitForCRDReady(apiextClient.RESTClient(), crds)
}

func WaitForCRDReady(restClient rest.Interface, crds []*crd_api.CustomResourceDefinition) error {
Expand Down
61 changes: 61 additions & 0 deletions vendor/kmodules.xyz/client-go/core/v1/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,23 @@ limitations under the License.
package v1

import (
"context"

meta_util "kmodules.xyz/client-go/meta"

"github.com/golang/glog"
"github.com/pkg/errors"
core "k8s.io/api/core/v1"
kerr "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/strategicpatch"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/pager"
kutil "kmodules.xyz/client-go"
)

Expand Down Expand Up @@ -112,3 +120,56 @@ func IsMaster(node core.Node) bool {
role16, ok16 := node.Labels["kubernetes.io/role"]
return ok17 || (ok16 && role16 == "master")
}

func Topology(kc kubernetes.Interface) (regions map[string][]string, instances map[string]int, err error) {
// TODO: Use https://github.com/kubernetes/client-go/blob/kubernetes-1.17.0/metadata/interface.go once upgraded to 1.17

mapRegion := make(map[string]sets.String)
instances = make(map[string]int)

lister := pager.New(pager.SimplePageFunc(func(opts metav1.ListOptions) (runtime.Object, error) {
return kc.CoreV1().Nodes().List(opts)
}))
err = lister.EachListItem(context.Background(), metav1.ListOptions{Limit: 100}, func(obj runtime.Object) error {
m, err := meta.Accessor(obj)
if err != nil {
return err
}

annotations := m.GetAnnotations()

os, _ := meta_util.GetStringVaultForKeys(annotations, "kubernetes.io/os", "beta.kubernetes.io/os")
if os != "linux" {
return nil
}
arch, _ := meta_util.GetStringVaultForKeys(annotations, "kubernetes.io/arch", "beta.kubernetes.io/arch")
if arch != "amd64" {
return nil
}

region, _ := meta_util.GetStringVaultForKeys(annotations, "topology.kubernetes.io/region", "failure-domain.beta.kubernetes.io/region")
zone, _ := meta_util.GetStringVaultForKeys(annotations, "topology.kubernetes.io/zone", "failure-domain.beta.kubernetes.io/zone")
if _, ok := mapRegion[region]; !ok {
mapRegion[region] = sets.NewString()
}
mapRegion[region].Insert(zone)

instance, _ := meta_util.GetStringVaultForKeys(annotations, "node.kubernetes.io/instance-type", "beta.kubernetes.io/instance-type")
if n, ok := instances[instance]; ok {
instances[instance] = n + 1
} else {
instances[instance] = 1
}

return nil
})
if err != nil {
return nil, nil, err
}

regions = make(map[string][]string)
for k, v := range mapRegion {
regions[k] = v.List()
}
return regions, instances, nil
}
15 changes: 14 additions & 1 deletion vendor/kmodules.xyz/client-go/discovery/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ func GetVersion(client discovery.DiscoveryInterface) (string, error) {
return gv.ToMutator().ResetMetadata().ResetPrerelease().String(), nil
}

func GetVersionInfo(client discovery.DiscoveryInterface) (int64, int64, int64, string, string, error) {
info, err := client.ServerVersion()
if err != nil {
return -1, -1, -1, "", "", err
}
gv, err := version.NewVersion(info.GitVersion)
if err != nil {
return -1, -1, -1, "", "", err
}
v := gv.ToMutator().ResetMetadata().ResetPrerelease()
return v.Major(), v.Minor(), v.Patch(), v.Prerelease(), v.Metadata(), nil
}

func GetBaseVersion(client discovery.DiscoveryInterface) (string, error) {
info, err := client.ServerVersion()
if err != nil {
Expand Down Expand Up @@ -97,7 +110,7 @@ var err62649_K1_10 = &KnownBug{URL: "https://github.com/kubernetes/kubernetes/pu
var err83778_K1_16 = &KnownBug{URL: "https://github.com/kubernetes/kubernetes/pull/83787", Fix: "upgrade to Kubernetes 1.16.2 or later."}

var (
DefaultConstraint = ">= 1.9.0"
DefaultConstraint = ">= 1.11.0"
DefaultBlackListedVersions map[string]error
DefaultBlackListedMultiMasterVersions = map[string]error{
"1.9.0": err62649_K1_9,
Expand Down
13 changes: 13 additions & 0 deletions vendor/kmodules.xyz/client-go/meta/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,16 @@ func ParseFor(key string, fn ParserFunc) GetFunc {
return fn(m, key)
}
}

func GetStringVaultForKeys(m map[string]string, key string, alts ...string) (string, error) {
if m == nil {
return "", kutil.ErrNotFound
}
keys := append([]string{key}, alts...)
for _, k := range keys {
if v, ok := m[k]; ok {
return v, nil
}
}
return "", kutil.ErrNotFound
}
Loading

0 comments on commit 17bd64f

Please sign in to comment.