Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[COST-5632] Cost Management Metrics Operator V3.3.2 updates #478

Merged
merged 66 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
3656a9e
update whats new in 3.3.0 (#360)
maskarb May 31, 2024
0497ada
update docs (#363)
maskarb May 31, 2024
fa8eb22
fix make downstream (#365)
maskarb May 31, 2024
52c0761
v3.3.0 bundle (#362)
maskarb Jul 8, 2024
3038c3a
Bump library/golang from 1.22.3 to 1.22.5 (#372)
dependabot[bot] Jul 8, 2024
f7bb525
Bump github.com/prometheus/common (#369)
dependabot[bot] Jul 8, 2024
6f7287c
Bump docker/build-push-action from 5 to 6 in the ci-dependencies grou…
dependabot[bot] Jul 8, 2024
77eeafe
[COST-5183] dont use csvReader.ReadAll to improve memory usage (#370)
maskarb Jul 8, 2024
f18d75f
update go in go.mod to 1.22 (#373)
maskarb Jul 9, 2024
1d41591
Bump the testing-framework group with 2 updates (#374)
dependabot[bot] Jul 29, 2024
144daf2
Bump github.com/onsi/gomega in the testing-framework group (#375)
dependabot[bot] Aug 8, 2024
4e7cca3
Update badges (#384)
djnakabaale Aug 8, 2024
1646f9f
Bump library/golang from 1.22.5 to 1.22.6 (#385)
dependabot[bot] Aug 8, 2024
b073187
update whats new in 3.3.1 (#388)
djnakabaale Aug 9, 2024
a77495c
make bundle for v3.3.1 (#389)
djnakabaale Aug 12, 2024
70b4449
[COST-5409] Specify correct toolchain version number in go.mod (#394)
djnakabaale Aug 16, 2024
1b91a61
Red Hat Konflux update koku-metrics-operator (#402)
red-hat-konflux[bot] Aug 20, 2024
82fd267
[COST-1418] Report fields description (#192)
djnakabaale Aug 21, 2024
83822c4
Red Hat Konflux purge koku-metrics-operator (#407)
red-hat-konflux[bot] Aug 26, 2024
4b02624
Red Hat Konflux update koku-metrics-operator (#408)
red-hat-konflux[bot] Aug 26, 2024
449a5a4
Update Konflux references (#410)
red-hat-konflux[bot] Aug 27, 2024
4f8361a
Update Konflux references (#411)
red-hat-konflux[bot] Aug 28, 2024
5be1d2f
Red Hat Konflux purge koku-metrics-operator (#412)
red-hat-konflux[bot] Aug 29, 2024
3758ea1
Red Hat Konflux update koku-metrics-operator (#422)
red-hat-konflux[bot] Sep 9, 2024
043cb00
[COST-5381] Konflux: Enable multi-arch builds (#426)
djnakabaale Sep 10, 2024
49ea6ce
Update Konflux references (#427)
red-hat-konflux[bot] Sep 10, 2024
c2673ec
Bump the testing-framework group across 1 directory with 2 updates (#…
dependabot[bot] Sep 11, 2024
2097b5d
Bump the prometheus group across 1 directory with 2 updates (#423)
dependabot[bot] Sep 11, 2024
00c9ac5
Update Konflux references (#428)
red-hat-konflux[bot] Sep 11, 2024
1d04dd7
[COST-5382] Konflux - prepare to add operator bundle component (#429)
djnakabaale Sep 12, 2024
96cd3bb
Red Hat Konflux update koku-metrics-operator-bundle (#431)
red-hat-konflux[bot] Sep 12, 2024
0ec274a
Update Konflux references (#430)
red-hat-konflux[bot] Sep 13, 2024
e34d15a
Update Konflux references (#435)
red-hat-konflux[bot] Sep 17, 2024
3fbb815
Update Konflux references (#438)
red-hat-konflux[bot] Sep 17, 2024
27ef02c
Update pre-commit hook golangci/golangci-lint to v1.61.0 (#437)
red-hat-konflux[bot] Sep 18, 2024
de1e839
Update Konflux references (#440)
red-hat-konflux[bot] Sep 18, 2024
99c55c6
Update Konflux references to e487185 (#441)
red-hat-konflux[bot] Sep 18, 2024
511f795
[COST-5382] konflux: update bundle pipeline and use brew registry (#434)
djnakabaale Sep 19, 2024
fd88ee6
[COST-5534] Add renovate config (#443)
djnakabaale Sep 19, 2024
9f060d3
Update Konflux references (#442)
red-hat-konflux[bot] Sep 19, 2024
e11d0c1
Update Konflux references (#445)
red-hat-konflux[bot] Sep 24, 2024
45667f9
Bump github.com/prometheus/client_golang in the prometheus group (#444)
dependabot[bot] Sep 24, 2024
bafed91
Update docker.io/library/golang Docker tag to v1.23.2 (#455)
red-hat-konflux[bot] Oct 2, 2024
474ce69
Update Konflux references (#454)
red-hat-konflux[bot] Oct 2, 2024
c78cd91
Bump appleboy/ssh-action in the ci-dependencies group (#457)
dependabot[bot] Oct 9, 2024
03ca342
Bump github.com/prometheus/common in the prometheus group (#458)
dependabot[bot] Oct 9, 2024
330f527
Update Konflux references to 37b9187 (#461)
red-hat-konflux[bot] Oct 10, 2024
78344ff
[COST-5544] Make leader election duration options configurable (#459)
djnakabaale Oct 11, 2024
2c7c2e0
Update Konflux references (#464)
red-hat-konflux[bot] Oct 15, 2024
6594dc5
Update Konflux references (#468)
red-hat-konflux[bot] Oct 23, 2024
1bde25e
Bump github.com/prometheus/client_golang in the prometheus group (#466)
dependabot[bot] Oct 23, 2024
e56a18c
Bump github.com/prometheus/common in the prometheus group (#470)
dependabot[bot] Oct 30, 2024
6b596b8
Update Konflux references (#472)
red-hat-konflux[bot] Oct 30, 2024
f3ad2d1
update go toolchain version (#465)
djnakabaale Nov 1, 2024
d053d3c
[COST-5607] update whats new in 3.3.2 (#473)
djnakabaale Nov 4, 2024
954fe20
Update Konflux references (#475)
red-hat-konflux[bot] Nov 5, 2024
1dd2f05
update features annotations (#476)
djnakabaale Nov 5, 2024
827410f
[COST-5631] bundle for v3.3.2 (#477)
djnakabaale Nov 5, 2024
064e96c
make downstream v3.3.2
djnakabaale Nov 7, 2024
3a17716
downstream v3.3.2 updates
djnakabaale Nov 7, 2024
429e009
fix typo
djnakabaale Nov 7, 2024
65c5668
cleanup
djnakabaale Nov 11, 2024
ffc8357
undo some make cmd changes
djnakabaale Nov 11, 2024
37123c6
remove bundle updates to follow in separate pr
djnakabaale Nov 11, 2024
1f31f61
fix filename
djnakabaale Nov 11, 2024
bb1963d
Merge branch 'downstream' into v3.3.2-merge-downstream
djnakabaale Nov 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci-manual.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ jobs:
fi
done
- name: go unit test in zvsi
uses: appleboy/ssh-action@v1.0.3
uses: appleboy/ssh-action@v1.1.0
with:
host: ${{ env.ZVSI_FIP_ADD }}
username: root
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
repos:
- repo: https://github.com/golangci/golangci-lint
rev: v1.54.2
rev: v1.61.0
hooks:
- id: golangci-lint
6 changes: 5 additions & 1 deletion .tekton/operator-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ metadata:
build.appstudio.redhat.com/pull_request_number: '{{pull_request_number}}'
build.appstudio.redhat.com/target_branch: '{{target_branch}}'
pipelinesascode.tekton.dev/max-keep-runs: "3"
pipelinesascode.tekton.dev/on-cel-expression: event == "pull_request" && target_branch == "downstream"
pipelinesascode.tekton.dev/on-cel-expression: event == "pull_request" && target_branch == "downstream" &&
(
".tekton/operator-pr.yaml".pathChanged() ||
"Dockerfile".pathChanged()
)
creationTimestamp: null
labels:
appstudio.openshift.io/application: costmanagement-metrics-operator
Expand Down
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ COPY --from=builder /etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt /etc
LABEL \
com.redhat.component="costmanagement-metrics-operator-container" \
description="Red Hat Cost Management Metrics Operator" \
distribution-scope="public" \
io.k8s.description="Operator to deploy and manage instances of Cost Management Metrics" \
io.k8s.display-name="Cost Management Metrics Operator" \
io.openshift.tags="cost,cost-management,prometheus,servicetelemetry,operators" \
maintainer="Cost Management <cost-mgmt@redhat.com>" \
name="costmanagement-metrics-operator" \
summary="Red Hat Cost Management Metrics Operator" \
version="3.3.1"
version="3.3.2" \
vendor="Red Hat, Inc."

ENTRYPOINT ["/manager"]
23 changes: 7 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# To re-generate a bundle for another specific version without changing the standard setup, you can:
# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2)
# - use environment variables to overwrite this value (e.g export VERSION=0.0.2)
PREVIOUS_VERSION ?= 3.3.0
VERSION ?= 3.3.1
PREVIOUS_VERSION ?= 3.3.1
VERSION ?= 3.3.2

MIN_KUBE_VERSION = 1.24.0
MIN_OCP_VERSION = 4.12
Expand Down Expand Up @@ -273,8 +273,7 @@ get-token-and-cert: ## Get a token from a running K8s cluster for local develop

.PHONY: bundle
bundle: operator-sdk manifests kustomize ## Generate bundle manifests and metadata, then validate generated files.
mkdir -p koku-metrics-operator/$(VERSION)/
rm -rf ./bundle koku-metrics-operator/$(VERSION)/
rm -rf ./bundle
$(OPERATOR_SDK) generate kustomize manifests
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMAGE_SHA)
$(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
Expand All @@ -289,16 +288,13 @@ bundle: operator-sdk manifests kustomize ## Generate bundle manifests and metada
ifdef NAMESPACE
$(YQ) -i '.metadata.namespace = "$(NAMESPACE)"' bundle/manifests/koku-metrics-operator.clusterserviceversion.yaml
endif
sed -i '' '/^COPY / s/bundle\///g' bundle.Dockerfile

cp -r ./bundle/ koku-metrics-operator/$(VERSION)/
cp bundle.Dockerfile koku-metrics-operator/$(VERSION)/Dockerfile
$(OPERATOR_SDK) bundle validate koku-metrics-operator/$(VERSION) --select-optional name=multiarch
$(OPERATOR_SDK) bundle validate koku-metrics-operator/$(VERSION) --select-optional suite=operatorframework
$(OPERATOR_SDK) bundle validate bundle/ --select-optional name=multiarch
$(OPERATOR_SDK) bundle validate bundle/ --select-optional suite=operatorframework

.PHONY: bundle-build
bundle-build: ## Build the bundle image.
cd koku-metrics-operator/$(VERSION) && $(CONTAINER_TOOL) build --platform linux/x86_64 -t $(BUNDLE_IMG) .
$(CONTAINER_TOOL) build --platform linux/x86_64 -t $(BUNDLE_IMG) --file bundle.Dockerfile .

.PHONY: bundle-push
bundle-push: ## Push the bundle image.
Expand Down Expand Up @@ -330,7 +326,6 @@ DOWNSTREAM_LOWERCASE = costmanagement
DOWNSTREAM_UPPERCASE = CostManagement
.PHONY: downstream
downstream: operator-sdk ## Generate the code changes necessary for the downstream image.
rm -rf $(REMOVE_FILES)
# sed replace everything but the Makefile
- LC_ALL=C find api/v1beta1 config/* docs/* -type f -exec sed -i '' 's/$(UPSTREAM_UPPERCASE)/$(DOWNSTREAM_UPPERCASE)/g' {} +
- LC_ALL=C find api/v1beta1 config/* docs/* -type f -exec sed -i '' 's/$(UPSTREAM_LOWERCASE)/$(DOWNSTREAM_LOWERCASE)/g' {} +
Expand All @@ -352,8 +347,7 @@ downstream: operator-sdk ## Generate the code changes necessary for the downstre

$(MAKE) manifests

mkdir -p costmanagement-metrics-operator/$(VERSION)/
rm -rf ./bundle costmanagement-metrics-operator/$(VERSION)/
rm -rf ./bundle

$(OPERATOR_SDK) generate kustomize manifests
cd config/manager && $(KUSTOMIZE) edit set image controller=$(DOWNSTREAM_IMAGE_TAG)
Expand All @@ -379,12 +373,9 @@ downstream: operator-sdk ## Generate the code changes necessary for the downstre

# scripts/update_bundle_dockerfile.py
cat downstream-assets/bundle.Dockerfile.txt >> bundle.Dockerfile
sed -i '' '/^COPY / s/bundle\///g' bundle.Dockerfile
sed -i '' 's/MIN_OCP_VERSION/$(MIN_OCP_VERSION)/g' bundle.Dockerfile
sed -i '' 's/REPLACE_VERSION/$(VERSION)/g' bundle.Dockerfile

cp -r ./bundle/ costmanagement-metrics-operator/$(VERSION)/
cp bundle.Dockerfile costmanagement-metrics-operator/$(VERSION)/Dockerfile

##@ Build Dependencies

Expand Down
2 changes: 1 addition & 1 deletion bundle.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ LABEL com.redhat.openshift.versions='v4.12'
LABEL name=openshift/costmanagement-metrics-operator-bundle
LABEL maintainer='<costmanagement@redhat.com>'
LABEL summary='Operator required to upload metrics data to the cost management service in console.redhat.com.'
LABEL version=3.3.1
LABEL version=3.3.1
80 changes: 77 additions & 3 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"flag"
"fmt"
"os"
"time"

configv1 "github.com/openshift/api/config/v1"
operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
Expand All @@ -29,8 +30,11 @@
)

var (
scheme = runtime.NewScheme()
setupLog = ctrl.Log.WithName("setup")
scheme = runtime.NewScheme()
setupLog = ctrl.Log.WithName("setup")
defaultLeaseDuration = 60 * time.Second
defaultRenewDeadline = 30 * time.Second
defaultRetryPeriod = 5 * time.Second
)

func init() {
Expand All @@ -48,14 +52,22 @@

func main() {
var metricsAddr string
var enableLeaderElection bool
var probeAddr string
var enableLeaderElection bool

Check warning on line 56 in cmd/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/main.go#L56

Added line #L56 was not covered by tests
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")

// fetch leader election configurations from environment variables
leaseDuration := getEnvVarDuration("LEADER_ELECTION_LEASE_DURATION", defaultLeaseDuration)
renewDeadline := getEnvVarDuration("LEADER_ELECTION_RENEW_DEADLINE", defaultRenewDeadline)
retryPeriod := getEnvVarDuration("LEADER_ELECTION_RETRY_PERIOD", defaultRetryPeriod)

// validate leader election
leaseDuration, renewDeadline, retryPeriod = validateLeaderElectionConfig(leaseDuration, renewDeadline, retryPeriod)

Check warning on line 70 in cmd/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/main.go#L63-L70

Added lines #L63 - L70 were not covered by tests
opts := zap.Options{
Development: true,
TimeEncoder: zapcore.RFC3339NanoTimeEncoder,
Expand Down Expand Up @@ -83,6 +95,9 @@

LeaderElection: enableLeaderElection,
LeaderElectionID: "91c624a5.openshift.io",
LeaseDuration: &leaseDuration,
RenewDeadline: &renewDeadline,
RetryPeriod: &retryPeriod,

Check warning on line 100 in cmd/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/main.go#L98-L100

Added lines #L98 - L100 were not covered by tests
Cache: cache.Options{DefaultNamespaces: map[string]cache.Config{watchNamespace: {}}},
})
if err != nil {
Expand Down Expand Up @@ -138,3 +153,62 @@
}
return ns, nil
}

// GetEnvVar returns the value from an environment variable
// or the provided default value if the variable does not exist.
func getEnvVarString(varName, defaultValue string) string {
if value, exists := os.LookupEnv(varName); exists {
return value
}
return defaultValue
}

// Returns time.Duration parsed from an env variable
// or the default value if the variable does not exist or does not parse into a duration.
func getEnvVarDuration(varName string, defaultValue time.Duration) time.Duration {
val := getEnvVarString(varName, "")

if val == "" {
return defaultValue
}

parsedVal, err := time.ParseDuration(val)
if err != nil {
setupLog.Error(err, "Invalid boolean format for environment variable", "Variable", varName, "Value", val)
return defaultValue
}
return parsedVal

}

// validateLeaderElectionConfig returns the Namespace the operator should be watching for changes
func validateLeaderElectionConfig(leaseDuration, renewDeadline, retryPeriod time.Duration) (time.Duration, time.Duration, time.Duration) {

// validate that renewDeadlne < leaseDuration
if renewDeadline >= leaseDuration {

setupLog.Info("Invalid configuration: LEADER_ELECTION_RENEW_DEADLINE must be less that LEADER_ELECTION_LEASE_DURATION; using default values",
"Provided LEADER_ELECTION_LEASE_DURATION", leaseDuration,
"Provided LEADER_ELECTION_RENEW_DEADLINE", renewDeadline,
"Default LEADER_ELECTION_LEASE_DURATION", defaultLeaseDuration,
"Default LEADER_ELECTION_RENEW_DEADLINE", defaultRenewDeadline,
)

leaseDuration = defaultLeaseDuration
renewDeadline = defaultRenewDeadline
}

// validate that retryPeriod < renewDeadlne
if retryPeriod >= renewDeadline {
setupLog.Info("Invalid configuration: LEADER_ELECTION_RETRY_PERIOD must be less that LEADER_ELECTION_RENEW_DEADLINE; using default values",
"Provided LEADER_ELECTION_RETRY_PERIOD", retryPeriod,
"Provided LEADER_ELECTION_RENEW_DEADLINE", renewDeadline,
"Default LEADER_ELECTION_RETRY_PERIOD", defaultRetryPeriod,
"Default LEADER_ELECTION_RENEW_DEADLINE", defaultRenewDeadline,
)
retryPeriod = defaultRetryPeriod
renewDeadline = defaultRenewDeadline
}

return leaseDuration, renewDeadline, retryPeriod
}
Loading