diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c99944aa..81b80dd4 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -33,9 +33,9 @@ jobs: with: go-version: '1.23' - name: golangci-lint - uses: golangci/golangci-lint-action@4696ba8babb6127d732c3c6dde519db15edab9ea # v6 + uses: golangci/golangci-lint-action@1481404843c368bc19ca9406f87d6e0fc97bdcfd # v7 with: - version: v1.62.2 + version: v2.0.2 build: name: CI Build strategy: diff --git a/.golangci.yaml b/.golangci.yaml index d824f40c..bcbd6d30 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -1,18 +1,35 @@ +version: "2" linters: - disable-all: true + default: none enable: - govet - - revive - - goimports - - misspell - ineffassign + - misspell + - revive + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + rules: + - linters: + - revive + path: _test.go + paths: + - /zz_generated_ + - third_party$ + - builtin$ + - examples$ +formatters: + enable: - gofmt -run: - timeout: 5m -issues: - exclude-rules: - - path: _test.go - linters: - - revive - exclude-files: - - "/zz_generated_" \ No newline at end of file + - goimports + exclusions: + generated: lax + paths: + - /zz_generated_ + - third_party$ + - builtin$ + - examples$ diff --git a/charts/rancher-backup-crd/templates/backup.yaml b/charts/rancher-backup-crd/templates/backup.yaml index 75ad5bf7..5cf1aad9 100644 --- a/charts/rancher-backup-crd/templates/backup.yaml +++ b/charts/rancher-backup-crd/templates/backup.yaml @@ -98,12 +98,11 @@ spec: lastTransitionTime: nullable: true type: string - lastUpdateTime: - nullable: true - type: string message: nullable: true type: string + observedGeneration: + type: integer reason: nullable: true type: string diff --git a/charts/rancher-backup-crd/templates/restore.yaml b/charts/rancher-backup-crd/templates/restore.yaml index 0f39ecf0..cf5ffd6c 100644 --- a/charts/rancher-backup-crd/templates/restore.yaml +++ b/charts/rancher-backup-crd/templates/restore.yaml @@ -88,12 +88,11 @@ spec: lastTransitionTime: nullable: true type: string - lastUpdateTime: - nullable: true - type: string message: nullable: true type: string + observedGeneration: + type: integer reason: nullable: true type: string diff --git a/e2e/backup/backup_test.go b/e2e/backup/backup_test.go index 3435ab84..fe8649c2 100644 --- a/e2e/backup/backup_test.go +++ b/e2e/backup/backup_test.go @@ -20,7 +20,6 @@ import ( . "github.com/onsi/gomega" "github.com/rancher/backup-restore-operator/e2e/test" backupv1 "github.com/rancher/backup-restore-operator/pkg/apis/resources.cattle.io/v1" - "github.com/rancher/wrangler/v3/pkg/condition" "github.com/samber/lo" "github.com/testcontainers/testcontainers-go" corev1 "k8s.io/api/core/v1" @@ -52,8 +51,8 @@ func isBackupSuccessul(b *backupv1.Backup) error { return err } - if !condition.Cond(backupv1.BackupConditionUploaded).IsTrue(bD) { - message := condition.Cond(backupv1.BackupConditionReady).GetMessage(bD) + if !backupv1.BackupConditionUploaded.ToK8sCondition().IsTrue(bD) { + message := backupv1.BackupConditionReady.ToK8sCondition().GetMessage(bD) return fmt.Errorf("backup %s did not upload %s", b.Name, message) } return nil diff --git a/e2e/backup/restore_test.go b/e2e/backup/restore_test.go index 08640373..3842555a 100644 --- a/e2e/backup/restore_test.go +++ b/e2e/backup/restore_test.go @@ -15,7 +15,6 @@ import ( promtestutil "github.com/prometheus/client_golang/prometheus/testutil" "github.com/rancher/backup-restore-operator/e2e/test" backupv1 "github.com/rancher/backup-restore-operator/pkg/apis/resources.cattle.io/v1" - "github.com/rancher/wrangler/v3/pkg/condition" "github.com/samber/lo" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/client" @@ -71,12 +70,12 @@ func isRestoreSuccessful(b *backupv1.Restore) error { return err } - if !condition.Cond(backupv1.RestoreConditionReady).IsTrue(bD) { - message := condition.Cond(backupv1.RestoreConditionReady).GetMessage(bD) + if !backupv1.RestoreConditionReady.ToK8sCondition().IsTrue(bD) { + message := backupv1.RestoreConditionReady.ToK8sCondition().GetMessage(bD) return fmt.Errorf("backup %s did not upload %s", b.Name, message) } - message := strings.ToLower(strings.TrimSpace(condition.Cond(backupv1.RestoreConditionReady).GetMessage(bD))) + message := strings.ToLower(strings.TrimSpace(backupv1.RestoreConditionReady.ToK8sCondition().GetMessage(bD))) if message != "completed" { return fmt.Errorf("The restore was not eventually completed : %s", message) } diff --git a/go.mod b/go.mod index d74be753..e4d78036 100644 --- a/go.mod +++ b/go.mod @@ -5,14 +5,15 @@ go 1.23.0 toolchain go1.23.4 replace ( + github.com/rancher/wrangler/v3 => github.com/mallardduck/rancher-wrangler/v3 v3.0.0-20250416182731-95ac3d169aa5 golang.org/x/crypto => golang.org/x/crypto v0.35.0 google.golang.org/grpc => google.golang.org/grpc v1.71.0 ) require ( github.com/minio/minio-go/v7 v7.0.87 - github.com/rancher/lasso v0.0.0-20241202185148-04649f379358 - github.com/rancher/wrangler/v3 v3.2.0-rc.2 + github.com/rancher/lasso v0.2.1 + github.com/rancher/wrangler/v3 v3.2.0 github.com/robfig/cron/v3 v3.0.1 github.com/sirupsen/logrus v1.9.3 github.com/stretchr/testify v1.10.0 @@ -38,7 +39,7 @@ require ( github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/dustin/go-humanize v1.0.1 // indirect github.com/emicklei/go-restful/v3 v3.12.1 // indirect - github.com/evanphx/json-patch v5.9.0+incompatible // indirect + github.com/evanphx/json-patch v5.9.11+incompatible // indirect github.com/felixge/httpsnoop v1.0.4 // indirect github.com/ghodss/yaml v1.0.0 // indirect github.com/go-logr/logr v1.4.2 // indirect @@ -83,14 +84,14 @@ require ( go.opentelemetry.io/proto/otlp v1.3.1 // indirect golang.org/x/crypto v0.33.0 // indirect golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect - golang.org/x/mod v0.22.0 // indirect + golang.org/x/mod v0.23.0 // indirect golang.org/x/net v0.35.0 // indirect golang.org/x/oauth2 v0.25.0 // indirect golang.org/x/sys v0.30.0 // indirect golang.org/x/term v0.29.0 // indirect golang.org/x/text v0.22.0 // indirect golang.org/x/time v0.7.0 // indirect - golang.org/x/tools v0.28.0 // indirect + golang.org/x/tools v0.30.0 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20250106144421-5f5ef82da422 // indirect google.golang.org/grpc v1.67.1 // indirect google.golang.org/protobuf v1.36.4 // indirect @@ -99,7 +100,7 @@ require ( gopkg.in/yaml.v3 v3.0.1 // indirect k8s.io/code-generator v0.32.1 // indirect k8s.io/component-base v0.32.1 // indirect - k8s.io/gengo v0.0.0-20240911193312-2b36238f13e9 // indirect + k8s.io/gengo v0.0.0-20250130153323-76c5745d3511 // indirect k8s.io/klog/v2 v2.130.1 // indirect k8s.io/kms v0.32.1 // indirect k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f // indirect diff --git a/go.sum b/go.sum index 0f3ea986..097c1b67 100644 --- a/go.sum +++ b/go.sum @@ -51,8 +51,8 @@ github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkp github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= github.com/emicklei/go-restful/v3 v3.12.1 h1:PJMDIM/ak7btuL8Ex0iYET9hxM3CI2sjZtzpL63nKAU= github.com/emicklei/go-restful/v3 v3.12.1/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= -github.com/evanphx/json-patch v5.9.0+incompatible h1:fBXyNpNMuTTDdquAq/uisOr2lShz4oaXpDTX2bLe7ls= -github.com/evanphx/json-patch v5.9.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= +github.com/evanphx/json-patch v5.9.11+incompatible h1:ixHHqfcGvxhWkniF1tWxBHA0yb4Z+d1UQi45df52xW8= +github.com/evanphx/json-patch v5.9.11+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= github.com/evanphx/json-patch/v5 v5.9.11 h1:/8HVnzMq13/3x9TPvjG08wUGqBTmZBsCWzjTM0wiaDU= github.com/evanphx/json-patch/v5 v5.9.11/go.mod h1:3j+LviiESTElxA4p3EMKAB9HXj3/XEtnUf6OZxqIQTM= github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= @@ -136,6 +136,8 @@ github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0V github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= +github.com/mallardduck/rancher-wrangler/v3 v3.0.0-20250416182731-95ac3d169aa5 h1:c6xTkG++ye/Jg1MdGmlV8We+A7l9dRzffTanehjLXEU= +github.com/mallardduck/rancher-wrangler/v3 v3.0.0-20250416182731-95ac3d169aa5/go.mod h1:i1BaMZxfmp9wehhGst1Ub9smG28OXF50+8O3S0oNrKk= github.com/minio/crc64nvme v1.0.1 h1:DHQPrYPdqK7jQG/Ls5CTBZWeex/2FMS3G5XGkycuFrY= github.com/minio/crc64nvme v1.0.1/go.mod h1:eVfm2fAzLlxMdUGc0EEBGSMmPwmXD5XiNRpnu9J3bvg= github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34= @@ -184,10 +186,8 @@ github.com/prometheus/common v0.62.0 h1:xasJaQlnWAeyHdUBeGjXmutelfJHWMRr+Fg4QszZ github.com/prometheus/common v0.62.0/go.mod h1:vyBcEuLSvWos9B1+CyL7JZ2up+uFzXhkqml0W5zIY1I= github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc= github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk= -github.com/rancher/lasso v0.0.0-20241202185148-04649f379358 h1:pJwgJXPt4fi0ysXsJcl28rvxhx/Z/9SNCDwFOEyeGu0= -github.com/rancher/lasso v0.0.0-20241202185148-04649f379358/go.mod h1:IxgTBO55lziYhTEETyVKiT8/B5Rg92qYiRmcIIYoPgI= -github.com/rancher/wrangler/v3 v3.2.0-rc.2 h1:weBa8NvAPFKFfkg3ZeD+V+B4yxCpaoiM9rPbvONKBVQ= -github.com/rancher/wrangler/v3 v3.2.0-rc.2/go.mod h1:Py71XA9ENufjKSGHr9n/pk+iMB6vU5ZrD1EOu9Q9nIs= +github.com/rancher/lasso v0.2.1 h1:SZTqMVQn8cAOqvwGBd1/EYOIJ/MGN+UfJrOWvHd4jHU= +github.com/rancher/lasso v0.2.1/go.mod h1:KSV3jBXfdXqdCuMm2uC8kKB9q/wuDYb3h0eHZoRjShM= github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs= github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro= github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII= @@ -262,8 +262,8 @@ go.opentelemetry.io/proto/otlp v1.3.1/go.mod h1:0X1WI4de4ZsLrrJNLAQbFeLCm3T7yBkR go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= -go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU= -go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc= +go.uber.org/mock v0.5.0 h1:KAMbZvZPyBPWgD14IrIQ38QCyjwpvVVV6K/bHl1IwQU= +go.uber.org/mock v0.5.0/go.mod h1:ge71pBPLYDk7QIi1LupWxdAykm7KIEFchiOqd6z7qMM= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= @@ -280,8 +280,8 @@ golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= -golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4= -golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= +golang.org/x/mod v0.23.0 h1:Zb7khfcRGKk+kqfxFaP5tZqCnDZMjC5VtUBs87Hr6QM= +golang.org/x/mod v0.23.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= @@ -350,8 +350,8 @@ golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= -golang.org/x/tools v0.28.0 h1:WuB6qZ4RPCQo5aP3WdKZS7i595EdWqWR8vqJTlwTVK8= -golang.org/x/tools v0.28.0/go.mod h1:dcIOrVd3mfQKTgrDVQHqCPMWy6lnhfhtX3hLXYVLfRw= +golang.org/x/tools v0.30.0 h1:BgcpHewrV5AUp2G9MebG4XPFI1E2W41zU1SaqVA9vJY= +golang.org/x/tools v0.30.0/go.mod h1:c347cR/OJfw5TI+GfX7RUPNMdDRRbjvYTS0jPyvsVtY= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -394,8 +394,8 @@ k8s.io/code-generator v0.32.1 h1:4lw1kFNDuFYXquTkB7Sl5EwPMUP2yyW9hh6BnFfRZFY= k8s.io/code-generator v0.32.1/go.mod h1:zaILfm00CVyP/6/pJMJ3zxRepXkxyDfUV5SNG4CjZI4= k8s.io/component-base v0.32.1 h1:/5IfJ0dHIKBWysGV0yKTFfacZ5yNV1sulPh3ilJjRZk= k8s.io/component-base v0.32.1/go.mod h1:j1iMMHi/sqAHeG5z+O9BFNCF698a1u0186zkjMZQ28w= -k8s.io/gengo v0.0.0-20240911193312-2b36238f13e9 h1:B0l8GxRsVc/tP/uCLBQdAjf2nBARx6u/r2OGuL/CyXQ= -k8s.io/gengo v0.0.0-20240911193312-2b36238f13e9/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E= +k8s.io/gengo v0.0.0-20250130153323-76c5745d3511 h1:4eL6zr5VCj71nu2nOuQ6j6m/kqh5WueXBN8daZkNe90= +k8s.io/gengo v0.0.0-20250130153323-76c5745d3511/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E= k8s.io/gengo/v2 v2.0.0-20240911193312-2b36238f13e9 h1:si3PfKm8dDYxgfbeA6orqrtLkvvIeH8UqffFJDl0bz4= k8s.io/gengo/v2 v2.0.0-20240911193312-2b36238f13e9/go.mod h1:EJykeLsmFC60UQbYJezXkEsG2FLrt0GPNkU5iK5GWxU= k8s.io/klog/v2 v2.2.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y= diff --git a/pkg/apis/resources.cattle.io/v1/types.go b/pkg/apis/resources.cattle.io/v1/types.go index acee9271..a29082e1 100644 --- a/pkg/apis/resources.cattle.io/v1/types.go +++ b/pkg/apis/resources.cattle.io/v1/types.go @@ -1,19 +1,19 @@ package v1 import ( - "github.com/rancher/wrangler/v3/pkg/genericcondition" + "github.com/rancher/wrangler/v3/pkg/condition" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" ) var ( - BackupConditionReady = "Ready" - BackupConditionUploaded = "Uploaded" - BackupConditionReconciling = "Reconciling" - BackupConditionStalled = "Stalled" - RestoreConditionReconciling = "Reconciling" - RestoreConditionStalled = "Stalled" - RestoreConditionReady = "Ready" + BackupConditionReady condition.Cond = "Ready" + BackupConditionUploaded condition.Cond = "Uploaded" + BackupConditionReconciling condition.Cond = "Reconciling" + BackupConditionStalled condition.Cond = "Stalled" + RestoreConditionReconciling condition.Cond = "Reconciling" + RestoreConditionStalled condition.Cond = "Stalled" + RestoreConditionReady condition.Cond = "Ready" ) // +genclient @@ -37,14 +37,19 @@ type BackupSpec struct { } type BackupStatus struct { - Conditions []genericcondition.GenericCondition `json:"conditions"` - LastSnapshotTS string `json:"lastSnapshotTs"` - NextSnapshotAt string `json:"nextSnapshotAt"` - ObservedGeneration int64 `json:"observedGeneration"` - StorageLocation string `json:"storageLocation"` - BackupType string `json:"backupType"` - Filename string `json:"filename"` - Summary string `json:"summary"` + // +listType=map + // +listMapKey=type + // +patchStrategy=merge + // +patchMergeKey=type + // +optional + Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"` + LastSnapshotTS string `json:"lastSnapshotTs"` + NextSnapshotAt string `json:"nextSnapshotAt"` + ObservedGeneration int64 `json:"observedGeneration"` + StorageLocation string `json:"storageLocation"` + BackupType string `json:"backupType"` + Filename string `json:"filename"` + Summary string `json:"summary"` } // +genclient @@ -121,9 +126,14 @@ type RestoreSpec struct { } type RestoreStatus struct { - Conditions []genericcondition.GenericCondition `json:"conditions,omitempty"` - RestoreCompletionTS string `json:"restoreCompletionTs"` - ObservedGeneration int64 `json:"observedGeneration"` - BackupSource string `json:"backupSource"` - Summary string `json:"summary"` + // +listType=map + // +listMapKey=type + // +patchStrategy=merge + // +patchMergeKey=type + // +optional + Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"` + RestoreCompletionTS string `json:"restoreCompletionTs"` + ObservedGeneration int64 `json:"observedGeneration"` + BackupSource string `json:"backupSource"` + Summary string `json:"summary"` } diff --git a/pkg/apis/resources.cattle.io/v1/zz_generated_deepcopy.go b/pkg/apis/resources.cattle.io/v1/zz_generated_deepcopy.go index a54f8d78..3a6cc5d1 100644 --- a/pkg/apis/resources.cattle.io/v1/zz_generated_deepcopy.go +++ b/pkg/apis/resources.cattle.io/v1/zz_generated_deepcopy.go @@ -22,7 +22,6 @@ limitations under the License. package v1 import ( - genericcondition "github.com/rancher/wrangler/v3/pkg/genericcondition" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" fields "k8s.io/apimachinery/pkg/fields" runtime "k8s.io/apimachinery/pkg/runtime" @@ -115,8 +114,10 @@ func (in *BackupStatus) DeepCopyInto(out *BackupStatus) { *out = *in if in.Conditions != nil { in, out := &in.Conditions, &out.Conditions - *out = make([]genericcondition.GenericCondition, len(*in)) - copy(*out, *in) + *out = make([]metav1.Condition, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } } return } @@ -358,8 +359,10 @@ func (in *RestoreStatus) DeepCopyInto(out *RestoreStatus) { *out = *in if in.Conditions != nil { in, out := &in.Conditions, &out.Conditions - *out = make([]genericcondition.GenericCondition, len(*in)) - copy(*out, *in) + *out = make([]metav1.Condition, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } } return } diff --git a/pkg/controllers/backup/controller.go b/pkg/controllers/backup/controller.go index 5ec94eca..59b6bf9a 100644 --- a/pkg/controllers/backup/controller.go +++ b/pkg/controllers/backup/controller.go @@ -16,9 +16,7 @@ import ( "github.com/rancher/backup-restore-operator/pkg/resourcesets" "github.com/rancher/backup-restore-operator/pkg/util" "github.com/rancher/backup-restore-operator/pkg/util/encryptionconfig" - "github.com/rancher/wrangler/v3/pkg/condition" v1core "github.com/rancher/wrangler/v3/pkg/generated/controllers/core/v1" - "github.com/rancher/wrangler/v3/pkg/genericcondition" "github.com/robfig/cron/v3" "github.com/sirupsen/logrus" @@ -197,11 +195,10 @@ func (h *handler) OnBackupChange(_ string, backup *v1.Backup) (*v1.Backup, error return err } // reset conditions to remove the reconciling condition, because as per kstatus lib its presence is considered an error - backup.Status.Conditions = []genericcondition.GenericCondition{} + backup.Status.Conditions = []k8sv1.Condition{} - condition.Cond(v1.BackupConditionReady).SetStatusBool(backup, true) - condition.Cond(v1.BackupConditionReady).Message(backup, "Completed") - condition.Cond(v1.BackupConditionUploaded).SetStatusBool(backup, true) + v1.BackupConditionReady.ToFluentBuilder(backup).True().SetMessage("Completed").Apply(backup) + v1.BackupConditionUploaded.ToFluentBuilder(backup).True().Apply(backup) backup.Status.LastSnapshotTS = time.Now().Format(time.RFC3339) if cronSchedule != nil { @@ -286,7 +283,7 @@ func (h *handler) performBackup(backup *v1.Backup, tmpBackupPath, backupFileName return err } - condition.Cond(v1.BackupConditionReady).SetStatusBool(backup, true) + v1.BackupConditionReady.ToFluentBuilder(backup).True().Apply(backup) gzipFile := backupFileName + ".tar.gz" if backup.Spec.EncryptionConfigSecretName != "" { @@ -343,8 +340,8 @@ func (h *handler) generateBackupFilename(backup *v1.Backup) (string, error) { // https://github.com/kubernetes-sigs/cli-utils/tree/master/pkg/kstatus // Reconciling and Stalled conditions are present and with a value of true whenever something unusual happens. func (h *handler) setReconcilingCondition(backup *v1.Backup, originalErr error) (*v1.Backup, error) { - if !condition.Cond(v1.BackupConditionReconciling).IsUnknown(backup) && condition.Cond(v1.BackupConditionReconciling).GetReason(backup) == "Error" { - reconcileMsg := condition.Cond(v1.BackupConditionReconciling).GetMessage(backup) + if !v1.BackupConditionReconciling.ToK8sCondition().IsUnknown(backup) && v1.BackupConditionReconciling.ToK8sCondition().GetReason(backup) == "Error" { + reconcileMsg := v1.BackupConditionReconciling.ToK8sCondition().GetMessage(backup) if strings.Contains(reconcileMsg, originalErr.Error()) { // no need to update object status again, because if another UpdateStatus is called without needing it, controller will // process the same object immediately without its default backoff @@ -358,9 +355,8 @@ func (h *handler) setReconcilingCondition(backup *v1.Backup, originalErr error) return err } - condition.Cond(v1.BackupConditionReconciling).SetStatusBool(updBackup, true) - condition.Cond(v1.BackupConditionReconciling).SetError(updBackup, "", originalErr) - condition.Cond(v1.BackupConditionReady).Message(updBackup, "Retrying") + v1.BackupConditionReconciling.ToFluentBuilder(updBackup).SetError("", originalErr).Apply(updBackup) + v1.BackupConditionReady.ToFluentBuilder(updBackup).SetMessage("Retrying").Apply(updBackup) _, err = h.backups.UpdateStatus(updBackup) return err diff --git a/pkg/controllers/restore/controller.go b/pkg/controllers/restore/controller.go index 9958a9dd..b0b34212 100644 --- a/pkg/controllers/restore/controller.go +++ b/pkg/controllers/restore/controller.go @@ -14,9 +14,7 @@ import ( "github.com/rancher/backup-restore-operator/pkg/util" "github.com/rancher/backup-restore-operator/pkg/util/encryptionconfig" lasso "github.com/rancher/lasso/pkg/client" - "github.com/rancher/wrangler/v3/pkg/condition" v1core "github.com/rancher/wrangler/v3/pkg/generated/controllers/core/v1" - "github.com/rancher/wrangler/v3/pkg/genericcondition" "github.com/rancher/wrangler/v3/pkg/slice" "github.com/sirupsen/logrus" @@ -284,9 +282,8 @@ func (h *handler) OnRestoreChange(_ string, restore *v1.Restore) (*v1.Restore, e } // reset conditions to remove the reconciling condition, because as per kstatus lib its presence is considered an error - restore.Status.Conditions = []genericcondition.GenericCondition{} - condition.Cond(v1.RestoreConditionReady).SetStatusBool(restore, true) - condition.Cond(v1.RestoreConditionReady).Message(restore, "Completed") + restore.Status.Conditions = []k8sv1.Condition{} + v1.RestoreConditionReady.ToFluentBuilder(restore).True().SetMessage("Completed").Apply(restore) restore.Status.RestoreCompletionTS = time.Now().Format(time.RFC3339) restore.Status.ObservedGeneration = restore.Generation @@ -808,8 +805,8 @@ func getGVR(resourceGVR string) schema.GroupVersionResource { // https://github.com/kubernetes-sigs/cli-utils/tree/master/pkg/kstatus // Reconciling and Stalled conditions are present and with a value of true whenever something unusual happens. func (h *handler) setReconcilingCondition(restore *v1.Restore, originalErr error) (*v1.Restore, error) { - if !condition.Cond(v1.RestoreConditionReconciling).IsUnknown(restore) && condition.Cond(v1.RestoreConditionReconciling).GetReason(restore) == "Error" { - reconcileMsg := condition.Cond(v1.RestoreConditionReconciling).GetMessage(restore) + if !v1.RestoreConditionReconciling.ToK8sCondition().IsUnknown(restore) && v1.RestoreConditionReconciling.ToK8sCondition().GetReason(restore) == "Error" { + reconcileMsg := v1.RestoreConditionReconciling.ToK8sCondition().GetMessage(restore) if strings.Contains(reconcileMsg, originalErr.Error()) || strings.EqualFold(reconcileMsg, originalErr.Error()) { // no need to update object status again, because if another UpdateStatus is called without needing it, controller will // process the same object immediately without its default backoff @@ -824,9 +821,8 @@ func (h *handler) setReconcilingCondition(restore *v1.Restore, originalErr error return err } - condition.Cond(v1.RestoreConditionReconciling).SetStatusBool(updRestore, true) - condition.Cond(v1.RestoreConditionReconciling).SetError(updRestore, "", originalErr) - condition.Cond(v1.BackupConditionReady).Message(updRestore, "Retrying") + v1.RestoreConditionReconciling.ToFluentBuilder(updRestore).SetError("", originalErr).Apply(updRestore) + v1.BackupConditionReady.ToFluentBuilder(updRestore).SetMessage("Retrying").Apply(updRestore) _, err = h.restores.UpdateStatus(updRestore) return err diff --git a/pkg/monitoring/metrics_test.go b/pkg/monitoring/metrics_test.go index e29df6ec..cd22b5f2 100644 --- a/pkg/monitoring/metrics_test.go +++ b/pkg/monitoring/metrics_test.go @@ -8,7 +8,6 @@ import ( promtestutil "github.com/prometheus/client_golang/prometheus/testutil" v1 "github.com/rancher/backup-restore-operator/pkg/apis/resources.cattle.io/v1" - "github.com/rancher/wrangler/v3/pkg/genericcondition" k8sv1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -162,7 +161,7 @@ func TestUpdateRestoreMetrics(t *testing.T) { { ObjectMeta: k8sv1.ObjectMeta{Name: "restore1"}, Status: v1.RestoreStatus{ - Conditions: []genericcondition.GenericCondition{ + Conditions: []k8sv1.Condition{ {Message: "Restore completed successfully"}, }, BackupSource: "s3", @@ -176,7 +175,7 @@ func TestUpdateRestoreMetrics(t *testing.T) { { ObjectMeta: k8sv1.ObjectMeta{Name: "restore2"}, Status: v1.RestoreStatus{ - Conditions: []genericcondition.GenericCondition{ + Conditions: []k8sv1.Condition{ {Message: "Restore failed"}, }, BackupSource: "s3", @@ -223,7 +222,7 @@ func TestUpdateBackupMetrics(t *testing.T) { Filename: "backup1.tar.gz", StorageLocation: "s3", LastSnapshotTS: "1627849200", - Conditions: []genericcondition.GenericCondition{ + Conditions: []k8sv1.Condition{ {Message: "Backup completed successfully"}, }, }, @@ -240,7 +239,7 @@ func TestUpdateBackupMetrics(t *testing.T) { Filename: "backup2.tar.gz", StorageLocation: "s3", LastSnapshotTS: "1627849300", - Conditions: []genericcondition.GenericCondition{ + Conditions: []k8sv1.Condition{ {Message: "Backup failed"}, }, },