Skip to content

Commit

Permalink
Update ocm mode detection
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha committed Oct 10, 2024
1 parent bb6baba commit fa267ad
Show file tree
Hide file tree
Showing 11 changed files with 238 additions and 139 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ require (
k8s.io/kube-openapi v0.0.0-20240703190633-0aa61b46e8c2
k8s.io/kubectl v0.30.1
k8s.io/utils v0.0.0-20240502163921-fe8a2dddb1d0
kmodules.xyz/client-go v0.30.22
kmodules.xyz/client-go v0.30.26
kmodules.xyz/fake-apiserver v0.0.1
kmodules.xyz/resource-metadata v0.19.0
kubepack.dev/lib-app v0.0.23-0.20241009153800-31c7b82c96b3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1055,8 +1055,8 @@ kmodules.xyz/apiversion v0.2.0 h1:vAQYqZFm4xu4pbB1cAdHbFEPES6EQkcR4wc06xdTOWk=
kmodules.xyz/apiversion v0.2.0/go.mod h1:oPX8g8LvlPdPX3Yc5YvCzJHQnw3YF/X4/jdW0b1am80=
kmodules.xyz/apply v0.29.0 h1:0OXGfE2IPuvXHk6uI9zp6KCYdBibx8mK4PEl0g3LZ44=
kmodules.xyz/apply v0.29.0/go.mod h1:bwToXErB+DC7/EEWjQVARCSbJBjGx5hIEuV1n0tC73g=
kmodules.xyz/client-go v0.30.22 h1:xo9vPI+tyK/uHCI3ek8z9eDQerswOPskNEQbBgBpZPw=
kmodules.xyz/client-go v0.30.22/go.mod h1:CAu+JlA8RVGtj6LQHu0Q1w2mnFUajuti49c7T1AvGdM=
kmodules.xyz/client-go v0.30.26 h1:cPoNid/Eq38EwznsZ27gu2AEXOjqcshn+/7kjlaaQNQ=
kmodules.xyz/client-go v0.30.26/go.mod h1:CAu+JlA8RVGtj6LQHu0Q1w2mnFUajuti49c7T1AvGdM=
kmodules.xyz/fake-apiserver v0.0.1 h1:OcL9kvVOSqh0pG8KhU72BWrlAE9j9+L0WJ7qNiXXpz8=
kmodules.xyz/fake-apiserver v0.0.1/go.mod h1:1kKm0V/WAKoSBbOpuzKrsfM5ydr/BXYWwZsNo4y4OvY=
kmodules.xyz/go-containerregistry v0.0.12 h1:Tl32QGmSqRVm9PUEb/f3dgDeu9zW5fVzt3qmAFIE37I=
Expand Down
8 changes: 8 additions & 0 deletions vendor/kmodules.xyz/client-go/api/v1/certificates.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ type CertificateSpec struct {
// +optional
Duration *metav1.Duration `json:"duration,omitempty" protobuf:"bytes,5,opt,name=duration"`

// Certificate renew before expiration duration
//
// Deprecated use `ReconfigureTLS` type OpsRequest instead.
//
// +deprecated
// +optional
RenewBefore *metav1.Duration `json:"renewBefore,omitempty" protobuf:"bytes,6,opt,name=renewBefore"`

// DNSNames is a list of subject alt names to be used on the Certificate.
// +optional
DNSNames []string `json:"dnsNames,omitempty" protobuf:"bytes,7,rep,name=dnsNames"`
Expand Down
290 changes: 172 additions & 118 deletions vendor/kmodules.xyz/client-go/api/v1/generated.pb.go

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions vendor/kmodules.xyz/client-go/api/v1/generated.proto

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

5 changes: 5 additions & 0 deletions vendor/kmodules.xyz/client-go/api/v1/zz_generated.deepcopy.go

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

13 changes: 11 additions & 2 deletions vendor/kmodules.xyz/client-go/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"reflect"
"strings"

"kmodules.xyz/client-go/meta"

"github.com/pkg/errors"
kerr "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
Expand Down Expand Up @@ -116,8 +118,15 @@ func CreateOrPatch(ctx context.Context, c client.Client, obj client.Object, tran
}

vt := kutil.VerbUnchanged
if cur.GetGeneration() != mod.GetGeneration() {
vt = kutil.VerbPatched
if mod.GetGeneration() > 0 {
if cur.GetGeneration() != mod.GetGeneration() {
vt = kutil.VerbPatched
}
} else {
// Secret, ServiceAccount etc resources do not use metadata.generation
if meta.ObjectHash(cur) != meta.ObjectHash(mod) {
vt = kutil.VerbPatched
}
}
assign(obj, mod)
return vt, nil
Expand Down
2 changes: 1 addition & 1 deletion vendor/kmodules.xyz/client-go/cluster/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func DetectClusterManager(kc client.Client, mappers ...meta.RESTMapper) kmapi.Cl
if IsOpenClusterHub(mapper) {
result |= kmapi.ClusterManagerOCMHub
}
if IsOpenClusterSpoke(mapper) {
if IsOpenClusterSpoke(kc) {
result |= kmapi.ClusterManagerOCMSpoke
}
if IsOpenClusterMulticlusterControlplane(mapper) {
Expand Down
18 changes: 10 additions & 8 deletions vendor/kmodules.xyz/client-go/cluster/ocm.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ limitations under the License.
package cluster

import (
"context"

"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/client"
)

func IsOpenClusterHub(mapper meta.RESTMapper) bool {
Expand All @@ -31,14 +35,12 @@ func IsOpenClusterHub(mapper meta.RESTMapper) bool {
return false
}

func IsOpenClusterSpoke(mapper meta.RESTMapper) bool {
if _, err := mapper.RESTMappings(schema.GroupKind{
Group: "operator.open-cluster-management.io",
Kind: "Klusterlet",
}); err == nil {
return true
}
return false
func IsOpenClusterSpoke(kc client.Client) bool {
var list unstructured.UnstructuredList
list.SetAPIVersion("operator.open-cluster-management.io/v1")
list.SetKind("Klusterlet")
err := kc.List(context.TODO(), &list)
return err == nil && len(list.Items) > 0
}

func IsOpenClusterMulticlusterControlplane(mapper meta.RESTMapper) bool {
Expand Down
25 changes: 19 additions & 6 deletions vendor/kmodules.xyz/client-go/meta/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ func ResourceHash(obj metav1.Object) string {
h := xxh3.New()
_, _ = h.WriteString(string(obj.GetUID()))
_, _ = h.WriteString(",")
_, _ = h.WriteString(strconv.FormatInt(obj.GetGeneration(), 10))
if obj.GetGeneration() > 0 {
_, _ = h.WriteString(strconv.FormatInt(obj.GetGeneration(), 10))
} else {
_, _ = h.WriteString(ObjectHash(obj))
}
return strconv.FormatUint(h.Sum64(), 10)
}

Expand All @@ -57,11 +61,20 @@ func ObjectHash(in metav1.Object) string {
obj["annotations"] = data
}

st := structs.New(in)
for _, field := range st.Fields() {
fieldName := field.Name()
if fieldName != "ObjectMeta" && fieldName != "TypeMeta" && fieldName != "Status" {
obj[fieldName] = field.Value()
u, isUnstructured := in.(*unstructured.Unstructured)
if isUnstructured {
for fieldName, v := range u.UnstructuredContent() {
if fieldName != "metadata" && fieldName != "apiVersion" && fieldName != "kind" && fieldName != "status" {
obj[fieldName] = v
}
}
} else {
st := structs.New(in)
for _, field := range st.Fields() {
fieldName := field.Name()
if fieldName != "ObjectMeta" && fieldName != "TypeMeta" && fieldName != "Status" {
obj[fieldName] = field.Value()
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1906,7 +1906,7 @@ kmodules.xyz/apiversion
# kmodules.xyz/apply v0.29.0
## explicit; go 1.21.5
kmodules.xyz/apply
# kmodules.xyz/client-go v0.30.22
# kmodules.xyz/client-go v0.30.26
## explicit; go 1.22.0
kmodules.xyz/client-go
kmodules.xyz/client-go/api/v1
Expand Down

0 comments on commit fa267ad

Please sign in to comment.