Skip to content

Commit

Permalink
Update Kubernetes v1.18.3 dependencies (#36)
Browse files Browse the repository at this point in the history
Signed-off-by: 1gtm <[email protected]>
  • Loading branch information
1gtm authored Aug 19, 2020
1 parent efe0fc5 commit 77a76a7
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 4 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
k8s.io/client-go v12.0.0+incompatible
k8s.io/component-base v0.18.3
k8s.io/kubectl v0.18.3
kmodules.xyz/client-go v0.0.0-20200817064010-b2e03dabff6b
kmodules.xyz/client-go v0.0.0-20200818171030-24b2ce405feb
kmodules.xyz/objectstore-api v0.0.0-20200521103120-92080446e04d
kmodules.xyz/offshoot-api v0.0.0-20200521035628-e135bf07b226
kmodules.xyz/openshift v0.0.0-20200522123204-ce4abf5433c8
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -955,8 +955,8 @@ kmodules.xyz/client-go v0.0.0-20200525195850-2fd180961371 h1:PPawDOMyDHGeDPN8j1e
kmodules.xyz/client-go v0.0.0-20200525195850-2fd180961371/go.mod h1:sY/eoe4ktxZEoHpr5NpAQ5s22VSwTE8psJtKVeVgLRY=
kmodules.xyz/client-go v0.0.0-20200630053911-20d035822d35 h1:gDzZWVvgAaEBzo4lxMGhPUWqySgFyFDkcqw3NskZiwQ=
kmodules.xyz/client-go v0.0.0-20200630053911-20d035822d35/go.mod h1:sY/eoe4ktxZEoHpr5NpAQ5s22VSwTE8psJtKVeVgLRY=
kmodules.xyz/client-go v0.0.0-20200817064010-b2e03dabff6b h1:2cbl+wEx2ffB/gD6szGQdjHzDhnzFKPHTKESJr8kxFM=
kmodules.xyz/client-go v0.0.0-20200817064010-b2e03dabff6b/go.mod h1:sY/eoe4ktxZEoHpr5NpAQ5s22VSwTE8psJtKVeVgLRY=
kmodules.xyz/client-go v0.0.0-20200818171030-24b2ce405feb h1:0yIIoTfkhR4JAgx8UyXbP7oAveVAOcf66+D+20Uj/Uc=
kmodules.xyz/client-go v0.0.0-20200818171030-24b2ce405feb/go.mod h1:sY/eoe4ktxZEoHpr5NpAQ5s22VSwTE8psJtKVeVgLRY=
kmodules.xyz/constants v0.0.0-20200506032633-a21e58ceec72/go.mod h1:DbiFk1bJ1KEO94t1SlAn7tzc+Zz95rSXgyUKa2nzPmY=
kmodules.xyz/crd-schema-fuzz v0.0.0-20200521005638-2433a187de95/go.mod h1:jpu8xFsDKd6kAWUAKk8oTu/GQGBWqhrcaDeOJdaCJnk=
kmodules.xyz/custom-resources v0.0.0-20200604135349-9e9f5c4fdba9 h1:W+k1qhU0W1rptia2PWPOb7IWUvWnf31EMnatXt7MW6w=
Expand Down
101 changes: 101 additions & 0 deletions vendor/kmodules.xyz/client-go/core/v1/events.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
Copyright AppsCode Inc. and Contributors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1

import (
"context"

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

func CreateOrPatchEvent(ctx context.Context, c kubernetes.Interface, meta metav1.ObjectMeta, transform func(*core.Event) *core.Event, opts metav1.PatchOptions) (*core.Event, kutil.VerbType, error) {
cur, err := c.CoreV1().Events(meta.Namespace).Get(ctx, meta.Name, metav1.GetOptions{})
if kerr.IsNotFound(err) {
glog.V(3).Infof("Creating Event %s/%s.", meta.Namespace, meta.Name)
out, err := c.CoreV1().Events(meta.Namespace).Create(ctx, transform(&core.Event{
TypeMeta: metav1.TypeMeta{
Kind: "Event",
APIVersion: core.SchemeGroupVersion.String(),
},
ObjectMeta: meta,
}), metav1.CreateOptions{
DryRun: opts.DryRun,
FieldManager: opts.FieldManager,
})
return out, kutil.VerbCreated, err
} else if err != nil {
return nil, kutil.VerbUnchanged, err
}
return PatchEvent(ctx, c, cur, transform, opts)
}

func PatchEvent(ctx context.Context, c kubernetes.Interface, cur *core.Event, transform func(*core.Event) *core.Event, opts metav1.PatchOptions) (*core.Event, kutil.VerbType, error) {
return PatchEventObject(ctx, c, cur, transform(cur.DeepCopy()), opts)
}

func PatchEventObject(ctx context.Context, c kubernetes.Interface, cur, mod *core.Event, opts metav1.PatchOptions) (*core.Event, kutil.VerbType, error) {
curJson, err := json.Marshal(cur)
if err != nil {
return nil, kutil.VerbUnchanged, err
}

modJson, err := json.Marshal(mod)
if err != nil {
return nil, kutil.VerbUnchanged, err
}

patch, err := strategicpatch.CreateTwoWayMergePatch(curJson, modJson, core.Event{})
if err != nil {
return nil, kutil.VerbUnchanged, err
}
if len(patch) == 0 || string(patch) == "{}" {
return cur, kutil.VerbUnchanged, nil
}
glog.V(3).Infof("Patching Event %s/%s with %s", cur.Namespace, cur.Name, string(patch))
out, err := c.CoreV1().Events(cur.Namespace).Patch(ctx, cur.Name, types.StrategicMergePatchType, patch, opts)
return out, kutil.VerbPatched, err
}

func TryUpdateEvent(ctx context.Context, c kubernetes.Interface, meta metav1.ObjectMeta, transform func(*core.Event) *core.Event, opts metav1.UpdateOptions) (result *core.Event, err error) {
attempt := 0
err = wait.PollImmediate(kutil.RetryInterval, kutil.RetryTimeout, func() (bool, error) {
attempt++
cur, e2 := c.CoreV1().Events(meta.Namespace).Get(ctx, meta.Name, metav1.GetOptions{})
if kerr.IsNotFound(e2) {
return false, e2
} else if e2 == nil {
result, e2 = c.CoreV1().Events(cur.Namespace).Update(ctx, transform(cur.DeepCopy()), opts)
return e2 == nil, nil
}
glog.Errorf("Attempt %d failed to update Event %s/%s due to %v.", attempt, cur.Namespace, cur.Name, e2)
return false, nil
})

if err != nil {
err = errors.Errorf("failed to update Event %s/%s after %d attempts due to %v", meta.Namespace, meta.Name, attempt, err)
}
return
}
5 changes: 5 additions & 0 deletions vendor/kmodules.xyz/client-go/meta/incluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ func Namespace() string {
if ns := os.Getenv("KUBE_NAMESPACE"); ns != "" {
return ns
}

if ns := os.Getenv("MY_POD_NAMESPACE"); ns != "" {
return ns
}

if data, err := ioutil.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/namespace"); err == nil {
if ns := strings.TrimSpace(string(data)); len(ns) > 0 {
return ns
Expand Down
2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ k8s.io/utils/integer
k8s.io/utils/io
k8s.io/utils/pointer
k8s.io/utils/trace
# kmodules.xyz/client-go v0.0.0-20200817064010-b2e03dabff6b
# kmodules.xyz/client-go v0.0.0-20200818171030-24b2ce405feb
kmodules.xyz/client-go
kmodules.xyz/client-go/api/v1
kmodules.xyz/client-go/apiextensions
Expand Down

0 comments on commit 77a76a7

Please sign in to comment.