Skip to content

Commit

Permalink
Update resource metadata
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha committed Jan 4, 2024
1 parent eb86820 commit f18d13f
Show file tree
Hide file tree
Showing 89 changed files with 42,021 additions and 3,789 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ require (
k8s.io/kube-state-metrics/v2 v2.7.0
kmodules.xyz/apiversion v0.2.0
kmodules.xyz/authorizer v0.29.0
kmodules.xyz/client-go v0.29.3
kmodules.xyz/client-go v0.29.5
kmodules.xyz/custom-resources v0.29.0
kmodules.xyz/go-containerregistry v0.0.12
kmodules.xyz/monitoring-agent-api v0.29.0
kmodules.xyz/resource-metadata v0.18.1
kmodules.xyz/resource-metadata v0.18.2-0.20240104094612-5669bfe26200
kmodules.xyz/resource-metrics v0.29.0
kmodules.xyz/sets v0.29.0
kubeops.dev/scanner v0.0.16
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3441,10 +3441,10 @@ kmodules.xyz/apiversion v0.2.0 h1:vAQYqZFm4xu4pbB1cAdHbFEPES6EQkcR4wc06xdTOWk=
kmodules.xyz/apiversion v0.2.0/go.mod h1:oPX8g8LvlPdPX3Yc5YvCzJHQnw3YF/X4/jdW0b1am80=
kmodules.xyz/authorizer v0.29.0 h1:ND8YGeyzExdZ8Bq5Z6UdFO794I6+oPuXbUMWyjlsYgM=
kmodules.xyz/authorizer v0.29.0/go.mod h1:UQmE3sNXeliebUqjEeD9QYiY+Na27/C5Bg/ekVRfQ3U=
kmodules.xyz/client-go v0.29.3 h1:vkQz4zaqWZ5wk+YQwl+C2LhzTXuJZcCUMvPpwdAzGTo=
kmodules.xyz/client-go v0.29.3/go.mod h1:xWlS/1zWkx1sIKCAkzULy9570mHZYi2exDECEoP1ek4=
kmodules.xyz/crd-schema-fuzz v0.29.0 h1:s6ATG46aWyP+SoBQU00/kL/7AS2AEWwkSPwVjU512vM=
kmodules.xyz/crd-schema-fuzz v0.29.0/go.mod h1:n708z9YQqLMP2KNLQVgBcRJw1QpSWLvpNCEi+KJDOYE=
kmodules.xyz/client-go v0.29.5 h1:iRl4MoV+96TM1csInOCWjn5xSOXzuYlil6CO40vXLHU=
kmodules.xyz/client-go v0.29.5/go.mod h1:pHuzpwzEcDUIGjVVvwz9N8lY+6A7HXwvs2d7NtK7Hho=
kmodules.xyz/crd-schema-fuzz v0.29.1 h1:zJTlWYOrT5dsVVHW8HGcnR/vaWfxQfNh11QwTtkYpcs=
kmodules.xyz/crd-schema-fuzz v0.29.1/go.mod h1:n708z9YQqLMP2KNLQVgBcRJw1QpSWLvpNCEi+KJDOYE=
kmodules.xyz/custom-resources v0.29.0 h1:RaDM2+wSVXiwIvLqmkTVYpwoH83AC8wruXe2p2rOZNY=
kmodules.xyz/custom-resources v0.29.0/go.mod h1:MzZyXtxdg1PDxGk3RTTO1Xv3KiVqZnIonSwmxVbagOY=
kmodules.xyz/go-containerregistry v0.0.12 h1:Tl32QGmSqRVm9PUEb/f3dgDeu9zW5fVzt3qmAFIE37I=
Expand All @@ -3453,8 +3453,8 @@ kmodules.xyz/monitoring-agent-api v0.29.0 h1:gpFl6OZrlMLb/ySMHdREI9EwGtnJ91oZBn9
kmodules.xyz/monitoring-agent-api v0.29.0/go.mod h1:iNbvaMTgVFOI5q2LJtGK91j4Dmjv4ZRiRdasGmWLKQI=
kmodules.xyz/offshoot-api v0.29.0 h1:GHLhxxT9jU1N8+FvOCCeJNyU5g0duYS46UGrs6AHNLY=
kmodules.xyz/offshoot-api v0.29.0/go.mod h1:5NxhBblXoDHWStx9HCDJR2KFTwYjEZ7i1Id3jelIunw=
kmodules.xyz/resource-metadata v0.18.1 h1:xRR3yvz8sOPAEdgyl2Uyac+9BrSkRqxCM4eNZPpomw4=
kmodules.xyz/resource-metadata v0.18.1/go.mod h1:t9zy5/xAD042zBn9Zf7igQKh9TSPa72B3kVMXdTQTUI=
kmodules.xyz/resource-metadata v0.18.2-0.20240104094612-5669bfe26200 h1:ta9BNEsHnrlViLboInxTuI8cKmD9AA4psQCaiXTmcQY=
kmodules.xyz/resource-metadata v0.18.2-0.20240104094612-5669bfe26200/go.mod h1:XsCdEKjfoulX29tMGviDhjT/jLl158uvMvXlKOhK1as=
kmodules.xyz/resource-metrics v0.29.0 h1:YBSVCbGdAugUqZK4igHu3fPhxvpYar4xejE6njryNM4=
kmodules.xyz/resource-metrics v0.29.0/go.mod h1:OuG/QobZ7o8GFHl/u3lqaUR0fDZDegxtV8Vdh+MNBD4=
kmodules.xyz/sets v0.29.0 h1:ZX/qOECzUob95JhhRtngJElHSlJ1UNNdwK4hTEy+nl0=
Expand Down
14 changes: 7 additions & 7 deletions vendor/kmodules.xyz/client-go/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,19 @@ type (
)

func CreateOrPatch(ctx context.Context, c client.Client, obj client.Object, transform TransformFunc, opts ...client.PatchOption) (kutil.VerbType, error) {
gvk, err := apiutil.GVKForObject(obj, c.Scheme())
if err != nil {
return kutil.VerbUnchanged, errors.Wrapf(err, "failed to get GVK for object %T", obj)
}

cur := obj.DeepCopyObject().(client.Object)
key := types.NamespacedName{
Namespace: cur.GetNamespace(),
Name: cur.GetName(),
}
err := c.Get(ctx, key, cur)
err = c.Get(ctx, key, cur)
if kerr.IsNotFound(err) {
klog.V(3).Infof("Creating %+v %s/%s.", obj.GetObjectKind().GroupVersionKind(), key.Namespace, key.Name)
klog.V(3).Infof("Creating %+v %s/%s.", gvk, key.Namespace, key.Name)

createOpts := make([]client.CreateOption, 0, len(opts))
for i := range opts {
Expand All @@ -96,11 +101,6 @@ func CreateOrPatch(ctx context.Context, c client.Client, obj client.Object, tran
return kutil.VerbUnchanged, err
}

gvk, err := apiutil.GVKForObject(obj, c.Scheme())
if err != nil {
return kutil.VerbUnchanged, errors.Wrapf(err, "failed to get GVK for object %T", obj)
}

_, unstructuredObj := obj.(*unstructured.Unstructured)

var patch client.Patch
Expand Down
126 changes: 126 additions & 0 deletions vendor/kmodules.xyz/client-go/core/v1/pod_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package v1

import (
"fmt"

core "k8s.io/api/core/v1"
)

Expand Down Expand Up @@ -108,3 +110,127 @@ func UpsertPodReadinessGateConditionType(readinessGates []core.PodReadinessGate,
ConditionType: conditionType,
})
}

const (
// NodeUnreachablePodReason is the reason on a pod when its state cannot be confirmed as kubelet is unresponsive
// on the node it is (was) running.
NodeUnreachablePodReason = "NodeLost"
)

// GetPodStatus returns pod status like kubectl
// Adapted from: https://github.com/kubernetes/kubernetes/blob/735804dc812ce647f8c130dced45b5ba4079b76e/pkg/printers/internalversion/printers.go#L825
func GetPodStatus(pod *core.Pod) string {
reason := string(pod.Status.Phase)
if pod.Status.Reason != "" {
reason = pod.Status.Reason
}

// If the Pod carries {type:PodScheduled, reason:WaitingForGates}, set reason to 'SchedulingGated'.
for _, condition := range pod.Status.Conditions {
if condition.Type == core.PodScheduled && condition.Reason == core.PodReasonSchedulingGated {
reason = core.PodReasonSchedulingGated
}
}

initContainers := make(map[string]*core.Container)
for i := range pod.Spec.InitContainers {
initContainers[pod.Spec.InitContainers[i].Name] = &pod.Spec.InitContainers[i]
}

initializing := false
for i := range pod.Status.InitContainerStatuses {
container := pod.Status.InitContainerStatuses[i]
switch {
case container.State.Terminated != nil && container.State.Terminated.ExitCode == 0:
continue
case isRestartableInitContainer(initContainers[container.Name]) &&
container.Started != nil && *container.Started:
continue
case container.State.Terminated != nil:
// initialization is failed
if len(container.State.Terminated.Reason) == 0 {
if container.State.Terminated.Signal != 0 {
reason = fmt.Sprintf("Init:Signal:%d", container.State.Terminated.Signal)
} else {
reason = fmt.Sprintf("Init:ExitCode:%d", container.State.Terminated.ExitCode)
}
} else {
reason = "Init:" + container.State.Terminated.Reason
}
initializing = true
case container.State.Waiting != nil && len(container.State.Waiting.Reason) > 0 && container.State.Waiting.Reason != "PodInitializing":
reason = "Init:" + container.State.Waiting.Reason
initializing = true
default:
reason = fmt.Sprintf("Init:%d/%d", i, len(pod.Spec.InitContainers))
initializing = true
}
break
}

if !initializing || isPodInitializedConditionTrue(&pod.Status) {
hasRunning := false
for i := len(pod.Status.ContainerStatuses) - 1; i >= 0; i-- {
container := pod.Status.ContainerStatuses[i]

if container.State.Waiting != nil && container.State.Waiting.Reason != "" {
reason = container.State.Waiting.Reason
} else if container.State.Terminated != nil && container.State.Terminated.Reason != "" {
reason = container.State.Terminated.Reason
} else if container.State.Terminated != nil && container.State.Terminated.Reason == "" {
if container.State.Terminated.Signal != 0 {
reason = fmt.Sprintf("Signal:%d", container.State.Terminated.Signal)
} else {
reason = fmt.Sprintf("ExitCode:%d", container.State.Terminated.ExitCode)
}
} else if container.Ready && container.State.Running != nil {
hasRunning = true
}
}

// change pod status back to "Running" if there is at least one container still reporting as "Running" status
if reason == "Completed" && hasRunning {
if hasPodReadyCondition(pod.Status.Conditions) {
reason = "Running"
} else {
reason = "NotReady"
}
}
}

if pod.DeletionTimestamp != nil && pod.Status.Reason == NodeUnreachablePodReason {
reason = "Unknown"
} else if pod.DeletionTimestamp != nil {
reason = "Terminating"
}

return reason
}

func hasPodReadyCondition(conditions []core.PodCondition) bool {
for _, condition := range conditions {
if condition.Type == core.PodReady && condition.Status == core.ConditionTrue {
return true
}
}
return false
}

func isRestartableInitContainer(initContainer *core.Container) bool {
if initContainer.RestartPolicy == nil {
return false
}

return *initContainer.RestartPolicy == core.ContainerRestartPolicyAlways
}

func isPodInitializedConditionTrue(status *core.PodStatus) bool {
for _, condition := range status.Conditions {
if condition.Type != core.PodInitialized {
continue
}

return condition.Status == core.ConditionTrue
}
return false
}
6 changes: 3 additions & 3 deletions vendor/kmodules.xyz/client-go/meta/preconditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
)

type PreConditionSet struct {
sets.String
sets.Set[string]
}

func (s PreConditionSet) PreconditionFunc() []mergepatch.PreconditionFunc {
Expand All @@ -36,7 +36,7 @@ func (s PreConditionSet) PreconditionFunc() []mergepatch.PreconditionFunc {
mergepatch.RequireMetadataKeyUnchanged("namespace"),
}

for _, field := range s.List() {
for _, field := range sets.List[string](s.Set) {
preconditions = append(preconditions,
RequireChainKeyUnchanged(field),
)
Expand All @@ -45,7 +45,7 @@ func (s PreConditionSet) PreconditionFunc() []mergepatch.PreconditionFunc {
}

func (s PreConditionSet) Error() error {
strList := strings.Join(s.List(), "\n\t")
strList := strings.Join(sets.List[string](s.Set), "\n\t")
return fmt.Errorf(strings.Join([]string{`At least one of the following was changed:
apiVersion
kind
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
apiVersion: meta.k8s.appscode.com/v1alpha1
kind: ResourceBlockDefinition
metadata:
creationTimestamp: null
name: helm.toolkit.fluxcd.io-v2beta2-helmreleases
spec:
blocks:
- actions:
create: Never
displayMode: List
kind: Connection
name: HelmRepository
query:
raw: |-
query Find($src: String!, $targetGroup: String!, $targetKind: String!) {
find(oid: $src) {
offshoot(group: "source.toolkit.fluxcd.io", kind: "HelmChart") {
refs: source(group: $targetGroup, kind: $targetKind) {
namespace
name
}
}
}
}
type: GraphQL
ref:
group: source.toolkit.fluxcd.io
kind: HelmRepository
- actions:
create: Never
displayMode: List
kind: Connection
name: HelmChart
query:
byLabel: offshoot
type: GraphQL
ref:
group: source.toolkit.fluxcd.io
kind: HelmChart
resource:
group: helm.toolkit.fluxcd.io
kind: HelmRelease
name: helmreleases
scope: Namespaced
version: v2beta2
Loading

0 comments on commit f18d13f

Please sign in to comment.