Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: kubernetes/client-go
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.27.5
Choose a base ref
...
head repository: kubernetes/client-go
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.27.6
Choose a head ref
  • 5 commits
  • 7 files changed
  • 3 contributors

Commits on Mar 27, 2023

  1. generate ReportingInstance and ReportingController in Event

    Kubernetes-commit: 9c142a62f746470d87592f77ac287b26d3c58a86
    HirazawaUi authored and k8s-publishing-bot committed Mar 27, 2023

    Unverified

    This user has not yet uploaded their public signing key.
    Copy the full SHA
    d55c4c3 View commit details

Commits on Aug 9, 2023

  1. Fallback to legacy discovery on a wider range of conditions in aggreg…

    …ator
    
    Kubernetes-commit: eafd330240d84f07d8d3ac25564c8244719b7bf2
    Jefftree authored and k8s-publishing-bot committed Aug 9, 2023

    Unverified

    This user has not yet uploaded their public signing key.
    Copy the full SHA
    68da234 View commit details

Commits on Aug 28, 2023

  1. Merge pull request #120067 from HirazawaUi/automated-cherry-pick-of-#…

    …116506-upstream-release-1.27
    
    Automated cherry pick of #116506: generate ReportingInstance and ReportingController in Event
    
    Kubernetes-commit: 350fe2642a33a98bed3e4bea038165ec1563696f
    k8s-publishing-bot committed Aug 28, 2023
    Copy the full SHA
    0ea0345 View commit details

Commits on Sep 4, 2023

  1. Merge pull request #120360 from Jefftree/automated-cherry-pick-of-#11…

    …9870-upstream-release-1.27
    
    Automated cherry pick of #119870: Fallback to legacy discovery on a wider range of conditions
    
    Kubernetes-commit: cf67dd0379b6da0428530ab1c384ab71e335b5a2
    k8s-publishing-bot committed Sep 4, 2023
    Copy the full SHA
    fa3c65e View commit details

Commits on Sep 13, 2023

  1. Copy the full SHA
    f2d9132 View commit details
Showing with 157 additions and 111 deletions.
  1. +25 −21 discovery/discovery_client.go
  2. +34 −12 discovery/discovery_client_test.go
  3. +4 −4 go.mod
  4. +4 −4 go.sum
  5. +3 −0 tools/record/event.go
  6. +84 −70 tools/record/event_test.go
  7. +3 −0 tools/record/events_cache_test.go
46 changes: 25 additions & 21 deletions discovery/discovery_client.go
Original file line number Diff line number Diff line change
@@ -67,6 +67,9 @@ const (
acceptDiscoveryFormats = AcceptV2Beta1 + "," + AcceptV1
)

// Aggregated discovery content-type GVK.
var v2Beta1GVK = schema.GroupVersionKind{Group: "apidiscovery.k8s.io", Version: "v2beta1", Kind: "APIGroupDiscoveryList"}

// DiscoveryInterface holds the methods that discover server-supported API groups,
// versions and resources.
type DiscoveryInterface interface {
@@ -260,16 +263,15 @@ func (d *DiscoveryClient) downloadLegacy() (
}

var resourcesByGV map[schema.GroupVersion]*metav1.APIResourceList
// Switch on content-type server responded with: aggregated or unaggregated.
switch {
case isV2Beta1ContentType(responseContentType):
// Based on the content-type server responded with: aggregated or unaggregated.
if isGVK, _ := ContentTypeIsGVK(responseContentType, v2Beta1GVK); isGVK {
var aggregatedDiscovery apidiscovery.APIGroupDiscoveryList
err = json.Unmarshal(body, &aggregatedDiscovery)
if err != nil {
return nil, nil, nil, err
}
apiGroupList, resourcesByGV, failedGVs = SplitGroupsAndResources(aggregatedDiscovery)
default:
} else {
// Default is unaggregated discovery v1.
var v metav1.APIVersions
err = json.Unmarshal(body, &v)
@@ -313,16 +315,15 @@ func (d *DiscoveryClient) downloadAPIs() (
apiGroupList := &metav1.APIGroupList{}
failedGVs := map[schema.GroupVersion]error{}
var resourcesByGV map[schema.GroupVersion]*metav1.APIResourceList
// Switch on content-type server responded with: aggregated or unaggregated.
switch {
case isV2Beta1ContentType(responseContentType):
// Based on the content-type server responded with: aggregated or unaggregated.
if isGVK, _ := ContentTypeIsGVK(responseContentType, v2Beta1GVK); isGVK {
var aggregatedDiscovery apidiscovery.APIGroupDiscoveryList
err = json.Unmarshal(body, &aggregatedDiscovery)
if err != nil {
return nil, nil, nil, err
}
apiGroupList, resourcesByGV, failedGVs = SplitGroupsAndResources(aggregatedDiscovery)
default:
} else {
// Default is unaggregated discovery v1.
err = json.Unmarshal(body, apiGroupList)
if err != nil {
@@ -333,26 +334,29 @@ func (d *DiscoveryClient) downloadAPIs() (
return apiGroupList, resourcesByGV, failedGVs, nil
}

// isV2Beta1ContentType checks of the content-type string is both
// "application/json" and contains the v2beta1 content-type params.
// ContentTypeIsGVK checks of the content-type string is both
// "application/json" and matches the provided GVK. An error
// is returned if the content type string is malformed.
// NOTE: This function is resilient to the ordering of the
// content-type parameters, as well as parameters added by
// intermediaries such as proxies or gateways. Examples:
//
// "application/json; g=apidiscovery.k8s.io;v=v2beta1;as=APIGroupDiscoveryList" = true
// "application/json; as=APIGroupDiscoveryList;v=v2beta1;g=apidiscovery.k8s.io" = true
// "application/json; as=APIGroupDiscoveryList;v=v2beta1;g=apidiscovery.k8s.io;charset=utf-8" = true
// "application/json" = false
// "application/json; charset=UTF-8" = false
func isV2Beta1ContentType(contentType string) bool {
// ("application/json; g=apidiscovery.k8s.io;v=v2beta1;as=APIGroupDiscoveryList", {apidiscovery.k8s.io, v2beta1, APIGroupDiscoveryList}) = (true, nil)
// ("application/json; as=APIGroupDiscoveryList;v=v2beta1;g=apidiscovery.k8s.io", {apidiscovery.k8s.io, v2beta1, APIGroupDiscoveryList}) = (true, nil)
// ("application/json; as=APIGroupDiscoveryList;v=v2beta1;g=apidiscovery.k8s.io;charset=utf-8", {apidiscovery.k8s.io, v2beta1, APIGroupDiscoveryList}) = (true, nil)
// ("application/json", any GVK) = (false, nil)
// ("application/json; charset=UTF-8", any GVK) = (false, nil)
// ("malformed content type string", any GVK) = (false, error)
func ContentTypeIsGVK(contentType string, gvk schema.GroupVersionKind) (bool, error) {
base, params, err := mime.ParseMediaType(contentType)
if err != nil {
return false
return false, err
}
return runtime.ContentTypeJSON == base &&
params["g"] == "apidiscovery.k8s.io" &&
params["v"] == "v2beta1" &&
params["as"] == "APIGroupDiscoveryList"
gvkMatch := runtime.ContentTypeJSON == base &&
params["g"] == gvk.Group &&
params["v"] == gvk.Version &&
params["as"] == gvk.Kind
return gvkMatch, nil
}

// ServerGroups returns the supported groups, with information like supported versions and the
46 changes: 34 additions & 12 deletions discovery/discovery_client_test.go
Original file line number Diff line number Diff line change
@@ -2763,54 +2763,76 @@ func TestAggregatedServerPreferredResources(t *testing.T) {
}

func TestDiscoveryContentTypeVersion(t *testing.T) {
v2beta1 := schema.GroupVersionKind{Group: "apidiscovery.k8s.io", Version: "v2beta1", Kind: "APIGroupDiscoveryList"}
tests := []struct {
contentType string
isV2Beta1 bool
gvk schema.GroupVersionKind
match bool
expectErr bool
}{
{
contentType: "application/json; g=apidiscovery.k8s.io;v=v2beta1;as=APIGroupDiscoveryList",
isV2Beta1: true,
gvk: v2beta1,
match: true,
expectErr: false,
},
{
// content-type parameters are not in correct order, but comparison ignores order.
contentType: "application/json; v=v2beta1;as=APIGroupDiscoveryList;g=apidiscovery.k8s.io",
isV2Beta1: true,
gvk: v2beta1,
match: true,
expectErr: false,
},
{
// content-type parameters are not in correct order, but comparison ignores order.
contentType: "application/json; as=APIGroupDiscoveryList;g=apidiscovery.k8s.io;v=v2beta1",
isV2Beta1: true,
gvk: v2beta1,
match: true,
expectErr: false,
},
{
// Ignores extra parameter "charset=utf-8"
contentType: "application/json; g=apidiscovery.k8s.io;v=v2beta1;as=APIGroupDiscoveryList;charset=utf-8",
isV2Beta1: true,
gvk: v2beta1,
match: true,
expectErr: false,
},
{
contentType: "application/json",
isV2Beta1: false,
gvk: v2beta1,
match: false,
expectErr: false,
},
{
contentType: "application/json; charset=UTF-8",
isV2Beta1: false,
gvk: v2beta1,
match: false,
expectErr: false,
},
{
contentType: "text/json",
isV2Beta1: false,
gvk: v2beta1,
match: false,
expectErr: false,
},
{
contentType: "text/html",
isV2Beta1: false,
gvk: v2beta1,
match: false,
expectErr: false,
},
{
contentType: "",
isV2Beta1: false,
gvk: v2beta1,
match: false,
expectErr: true,
},
}

for _, test := range tests {
isV2Beta1 := isV2Beta1ContentType(test.contentType)
assert.Equal(t, test.isV2Beta1, isV2Beta1)
match, err := ContentTypeIsGVK(test.contentType, test.gvk)
assert.Equal(t, test.expectErr, err != nil)
assert.Equal(t, test.match, match)
}
}

8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -24,8 +24,8 @@ require (
golang.org/x/term v0.6.0
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8
google.golang.org/protobuf v1.28.1
k8s.io/api v0.0.0-20230810162708-366ac8e0b0e7
k8s.io/apimachinery v0.0.0-20230716201907-f46cb694b153
k8s.io/api v0.27.6
k8s.io/apimachinery v0.27.6
k8s.io/klog/v2 v2.90.1
k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f
k8s.io/utils v0.0.0-20230209194617-a36077c30491
@@ -59,6 +59,6 @@ require (
)

replace (
k8s.io/api => k8s.io/api v0.0.0-20230810162708-366ac8e0b0e7
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20230716201907-f46cb694b153
k8s.io/api => k8s.io/api v0.27.6
k8s.io/apimachinery => k8s.io/apimachinery v0.27.6
)
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -477,10 +477,10 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
k8s.io/api v0.0.0-20230810162708-366ac8e0b0e7 h1:QSCbO4nqtz+R8QJiF7euz3a1G8nI6aCFnefGxDiESI0=
k8s.io/api v0.0.0-20230810162708-366ac8e0b0e7/go.mod h1:BWkQci1GNcqqb+qGAExwyIXADZGrGeKn7HyT0uocwWM=
k8s.io/apimachinery v0.0.0-20230716201907-f46cb694b153 h1:x2PSNcoDv7r2/kHjMWs1jAWYQjINJElAVG7B0mEOF2E=
k8s.io/apimachinery v0.0.0-20230716201907-f46cb694b153/go.mod h1:XNfZ6xklnMCOGGFNqXG7bUrQCoR04dh/E7FprV6pb+E=
k8s.io/api v0.27.6 h1:PBWu/lywJe2qQcshMjubzcBg7+XDZOo7O8JJAWuYtUo=
k8s.io/api v0.27.6/go.mod h1:AQYj0UsFCp3qJE7bOVnUuy4orCsXVkvHefnbYQiNWgk=
k8s.io/apimachinery v0.27.6 h1:mGU8jmBq5o8mWBov+mLjdTBcU+etTE19waies4AQ6NE=
k8s.io/apimachinery v0.27.6/go.mod h1:XNfZ6xklnMCOGGFNqXG7bUrQCoR04dh/E7FprV6pb+E=
k8s.io/klog/v2 v2.90.1 h1:m4bYOKall2MmOiRaR1J+We67Do7vm9KiQVlT96lnHUw=
k8s.io/klog/v2 v2.90.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0=
k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f h1:2kWPakN3i/k81b0gvD5C5FJ2kxm1WrQFanWchyKuqGg=
3 changes: 3 additions & 0 deletions tools/record/event.go
Original file line number Diff line number Diff line change
@@ -357,6 +357,9 @@ func (recorder *recorderImpl) generateEvent(object runtime.Object, annotations m
event := recorder.makeEvent(ref, annotations, eventtype, reason, message)
event.Source = recorder.source

event.ReportingInstance = recorder.source.Host
event.ReportingController = recorder.source.Component

// NOTE: events should be a non-blocking operation, but we also need to not
// put this in a goroutine, otherwise we'll race to write to a closed channel
// when we go to shut down this broadcaster. Just drop events if we get overloaded,
Loading