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

Add numbers to all Errorfs #560

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ make build
make local
```

If you need an error code, you can generate that using e.g `shuf -i 0-9999 -n 1` and pad with zeroes.
Error codes are chosen by random, uniform sampling on that interval. Pick any number, make sure its not a duplicate.

### Kafka & Protobuf

Whenever an Application is synchronized, a [deployment event message](https://github.com/navikt/protos/blob/master/deployment/deployment.proto)
Expand Down
2 changes: 1 addition & 1 deletion cmd/naiserator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func run() error {
}

if len(cfg.GatewayMappings) == 0 {
return fmt.Errorf("no gateway mappings defined. Will not be able to set the right gateway on the ingress")
return fmt.Errorf("NAISERATOR-1058: no gateway mappings defined. Will not be able to set the right gateway on the ingress")
}

listers := naiserator_scheme.GenericListers()
Expand Down
12 changes: 6 additions & 6 deletions pkg/generators/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var _ synchronizer.Generator = &Application{}
func (g *Application) Prepare(ctx context.Context, source resource.Source, kube client.Client) (interface{}, error) {
app, ok := source.(*nais_io_v1alpha1.Application)
if !ok {
return nil, fmt.Errorf("BUG: this generator accepts only nais_io_v1alpha1.Application objects")
return nil, fmt.Errorf("NAISERATOR-3237: BUG: this generator accepts only nais_io_v1alpha1.Application objects")
}

o := &Options{
Expand All @@ -67,14 +67,14 @@ func (g *Application) Prepare(ctx context.Context, source resource.Source, kube
deploy := &appsv1.Deployment{}
err := kube.Get(ctx, key, deploy)
if err != nil && !errors.IsNotFound(err) {
return nil, fmt.Errorf("query existing deployment: %s", err)
return nil, fmt.Errorf("NAISERATOR-2760: query existing deployment: %s", err)
}

// Disallow creating application resources if there is a Naisjob with the same name.
job := &nais_io_v1.Naisjob{}
err = kube.Get(ctx, key, job)
if err == nil {
return nil, fmt.Errorf("cannot create an Application with name '%s' because a Naisjob with that name exists", source.GetName())
return nil, fmt.Errorf("NAISERATOR-0916: cannot create an Application with name '%s' because a Naisjob with that name exists", source.GetName())
}

o.NumReplicas = numReplicas(deploy, app.GetReplicas().Min, app.GetReplicas().Max)
Expand All @@ -84,7 +84,7 @@ func (g *Application) Prepare(ctx context.Context, source resource.Source, kube
namespace := &corev1.Namespace{}
err = kube.Get(ctx, namespaceKey, namespace)
if err != nil && !errors.IsNotFound(err) {
return nil, fmt.Errorf("query existing namespace: %s", err)
return nil, fmt.Errorf("NAISERATOR-7805: query existing namespace: %s", err)
}

// Auto-detect Google Team Project ID
Expand Down Expand Up @@ -123,12 +123,12 @@ func (g *Application) Generate(source resource.Source, config interface{}) (reso

app, ok := source.(*nais_io_v1alpha1.Application)
if !ok {
return nil, fmt.Errorf("BUG: CreateApplication only accepts nais_io_v1alpha1.Application objects; fix your code")
return nil, fmt.Errorf("NAISERATOR-7774: BUG: CreateApplication only accepts nais_io_v1alpha1.Application objects; fix your code")
}

cfg, ok := config.(*Options)
if !ok {
return nil, fmt.Errorf("BUG: Application generator called without correct configuration object; fix your code")
return nil, fmt.Errorf("NAISERATOR-0175: BUG: Application generator called without correct configuration object; fix your code")
}

ast := resource.NewAst()
Expand Down
14 changes: 7 additions & 7 deletions pkg/generators/naisjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var _ synchronizer.Generator = &Naisjob{}
func (g *Naisjob) Prepare(ctx context.Context, source resource.Source, kube client.Client) (interface{}, error) {
job, ok := source.(*nais_io_v1.Naisjob)
if !ok {
return nil, fmt.Errorf("BUG: this generator accepts only nais_io_v1.Naisjob objects")
return nil, fmt.Errorf("NAISERATOR-9325: BUG: this generator accepts only nais_io_v1.Naisjob objects")
}

o := &Options{
Expand All @@ -53,7 +53,7 @@ func (g *Naisjob) Prepare(ctx context.Context, source resource.Source, kube clie
namespace := &corev1.Namespace{}
err := kube.Get(ctx, namespaceKey, namespace)
if err != nil && !errors.IsNotFound(err) {
return nil, fmt.Errorf("query existing namespace: %s", err)
return nil, fmt.Errorf("NAISERATOR-9777: query existing namespace: %s", err)
}

// Disallow creating Naisjob resources if there is an Application with the same name.
Expand All @@ -64,7 +64,7 @@ func (g *Naisjob) Prepare(ctx context.Context, source resource.Source, kube clie
app := &nais_io_v1alpha1.Application{}
err = kube.Get(ctx, key, app)
if err == nil {
return nil, fmt.Errorf("cannot create a Naisjob with name '%s' because an Application with that name exists", source.GetName())
return nil, fmt.Errorf("NAISERATOR-2468: cannot create a Naisjob with name '%s' because an Application with that name exists", source.GetName())
}

// Auto-detect Google Team Project ID
Expand Down Expand Up @@ -101,12 +101,12 @@ func (g *Naisjob) Prepare(ctx context.Context, source resource.Source, kube clie
func (g *Naisjob) Generate(source resource.Source, config interface{}) (resource.Operations, error) {
naisjob, ok := source.(*nais_io_v1.Naisjob)
if !ok {
return nil, fmt.Errorf("BUG: generator only accepts nais_io_v1.Naisjob objects, fix your caller")
return nil, fmt.Errorf("NAISERATOR-6589: BUG: generator only accepts nais_io_v1.Naisjob objects, fix your caller")
}

cfg, ok := config.(*Options)
if !ok {
return nil, fmt.Errorf("BUG: Application generator called without correct configuration object; fix your code")
return nil, fmt.Errorf("NAISERATOR-0404: BUG: Application generator called without correct configuration object; fix your code")
}

ast := resource.NewAst()
Expand Down Expand Up @@ -154,14 +154,14 @@ func (g *Naisjob) Generate(source resource.Source, config interface{}) (resource

if naisjob.Spec.Schedule == "" {
if err := batch.DeleteCronJob(naisjob, ast); err != nil {
return nil, fmt.Errorf("convert to job: %w", err)
return nil, fmt.Errorf("NAISERATOR-9392: convert to job: %w", err)
}
if err := batch.CreateJob(naisjob, ast, cfg); err != nil {
return nil, err
}
} else {
if err := batch.DeleteJob(naisjob, ast); err != nil {
return nil, fmt.Errorf("convert to cronjob: %w", err)
return nil, fmt.Errorf("NAISERATOR-4499: convert to cronjob: %w", err)
}
if err := batch.CreateCronJob(naisjob, ast, cfg); err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/generators/sqlinstance.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func prepareSqlInstance(ctx context.Context, kube client.Client, key client.Obje
err := kube.Get(ctx, key, sqlinstance)
if err != nil {
if !errors.IsNotFound(err) {
return fmt.Errorf("query existing sqlinstance: %s", err)
return fmt.Errorf("NAISERATOR-7093: query existing sqlinstance: %s", err)
}
o.SqlInstance.exists = false
} else {
Expand Down
8 changes: 4 additions & 4 deletions pkg/naiserator/config/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ func (v Vault) Validate() error {
var result = &multierror.Error{}

if len(v.Address) == 0 {
multierror.Append(result, fmt.Errorf("vault address not found in environment"))
multierror.Append(result, fmt.Errorf("NAISERATOR-7612: vault address not found in environment"))
}

if len(v.InitContainerImage) == 0 {
multierror.Append(result, fmt.Errorf("vault init container image not found in environment"))
multierror.Append(result, fmt.Errorf("NAISERATOR-8218: vault init container image not found in environment"))
}

if len(v.AuthPath) == 0 {
multierror.Append(result, fmt.Errorf("vault auth path not found in environment"))
multierror.Append(result, fmt.Errorf("NAISERATOR-9099: vault auth path not found in environment"))
}

if len(v.KeyValuePath) == 0 {
multierror.Append(result, fmt.Errorf("vault kv path not specified"))
multierror.Append(result, fmt.Errorf("NAISERATOR-3997: vault kv path not specified"))
}

return result.ErrorOrNil()
Expand Down
4 changes: 2 additions & 2 deletions pkg/proxyopts/proxyopts.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func httpOpts(flags javaOptions, proxyURL string) (javaOptions, error) {
}

if len(u.Hostname()) == 0 || len(u.Port()) == 0 {
return flags, fmt.Errorf("if specifying a proxy URL, both hostname and port is required")
return flags, fmt.Errorf("NAISERATOR-7260: if specifying a proxy URL, both hostname and port is required")
}

flags = append(flags, newJavaOption("http.proxyHost", u.Hostname()))
Expand Down Expand Up @@ -85,7 +85,7 @@ func JavaProxyOptions(proxyURL, noProxy string) (s string, err error) {

flags, err = httpOpts(flags, proxyURL)
if err != nil {
err = fmt.Errorf("error in parsing proxy URL: %s", err)
err = fmt.Errorf("NAISERATOR-4196: error in parsing proxy URL: %s", err)
return
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/resourcecreator/aiven/influxdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func Influx(ast *resource.Ast, influx *nais_io_v1.Influx, aivenApp *aiven_nais_i

if credentialsEnabled {
if influx.Instance == "" {
return false, fmt.Errorf("Influx enabled, but no instance specified")
return false, fmt.Errorf("NAISERATOR-1578: Influx enabled, but no instance specified")
}

addInfluxEnvVariables(ast, aivenApp.Spec.SecretName)
Expand Down
2 changes: 1 addition & 1 deletion pkg/resourcecreator/aiven/opensearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func OpenSearch(ast *resource.Ast, openSearch *nais_io_v1.OpenSearch, aivenApp *
}

if openSearch.Instance == "" {
return false, fmt.Errorf("OpenSearch enabled, but no instance specified")
return false, fmt.Errorf("NAISERATOR-7091: OpenSearch enabled, but no instance specified")
}

addOpenSearchEnvVariables(ast, aivenApp.Spec.SecretName)
Expand Down
4 changes: 2 additions & 2 deletions pkg/resourcecreator/aiven/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ func Redis(ast *resource.Ast, config Config, source Source, aivenApp *aiven_nais
}

if len(config.GetAivenProject()) == 0 {
return false, fmt.Errorf("aiven project not defined for this cluster; needed for Redis")
return false, fmt.Errorf("NAISERATOR-6450: aiven project not defined for this cluster; needed for Redis")
}

for _, redis := range redises {
if redis.Instance == "" {
return false, fmt.Errorf("Redis requires instance name")
return false, fmt.Errorf("NAISERATOR-1564: Redis requires instance name")
}

addRedisEnvVariables(ast, aivenApp.Spec.SecretName, redis.Instance)
Expand Down
6 changes: 3 additions & 3 deletions pkg/resourcecreator/azure/azureadapplication.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func Create(source Source, ast *resource.Ast, config Config) error {
}

if !config.IsAzureratorEnabled() {
return fmt.Errorf("azure ad is not available in this cluster")
return fmt.Errorf("NAISERATOR-8848: azure ad is not available in this cluster")
}

azureAdApplication, err := application(source, config)
Expand Down Expand Up @@ -111,12 +111,12 @@ func application(source Source, config Config) (*nais_io_v1.AzureAdApplication,

func sidecar(source Source, ast *resource.Ast, config Config, azureApp *nais_io_v1.AzureAdApplication) error {
if !config.IsWonderwallEnabled() {
return fmt.Errorf("azure ad sidecar is not enabled for this cluster")
return fmt.Errorf("NAISERATOR-8373: azure ad sidecar is not enabled for this cluster")
}

ingresses := source.GetIngress()
if len(ingresses) == 0 {
return fmt.Errorf("must have at least 1 ingress to use Azure AD sidecar")
return fmt.Errorf("NAISERATOR-1512: must have at least 1 ingress to use Azure AD sidecar")
}

// ensure that the ingress is added to the configured Azure AD reply URLs
Expand Down
4 changes: 2 additions & 2 deletions pkg/resourcecreator/deployment/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func Create(app Source, ast *resource.Ast, cfg Config) error {
objectMeta := resource.CreateObjectMeta(app)
spec, err := deploymentSpec(app, ast, cfg)
if err != nil {
return fmt.Errorf("create deployment: %w", err)
return fmt.Errorf("NAISERATOR-4662: create deployment: %w", err)
}

if val, ok := app.GetAnnotations()["kubernetes.io/change-cause"]; ok {
Expand All @@ -60,7 +60,7 @@ func Create(app Source, ast *resource.Ast, cfg Config) error {
if app.GetTTL() != "" {
d, err := time.ParseDuration(app.GetTTL())
if err != nil {
return fmt.Errorf("parsing TTL: %w", err)
return fmt.Errorf("NAISERATOR-4232: parsing TTL: %w", err)
}

objectMeta.Annotations["euthanaisa.nais.io/kill-after"] = time.Now().Add(d).Format(time.RFC3339)
Expand Down
2 changes: 1 addition & 1 deletion pkg/resourcecreator/google/gcp/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func Create(source Source, ast *resource.Ast, cfg Config) error {

if gcp != nil && len(teamProjectID) == 0 {
// We're not currently in a team namespace with corresponding GCP team project
return fmt.Errorf("GCP resources requested, but no team project ID annotation set on namespace %s (not running on GCP?)", source.GetNamespace())
return fmt.Errorf("NAISERATOR-9843: GCP resources requested, but no team project ID annotation set on namespace %s (not running on GCP?)", source.GetNamespace())
}

if !cfg.IsCNRMEnabled() && len(projectID) == 0 {
Expand Down
4 changes: 2 additions & 2 deletions pkg/resourcecreator/google/iam/policymember.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func policyMember(source resource.Source, policy nais_io_v1.CloudIAMPermission,
func createName(appName string, policy nais_io_v1.CloudIAMPermission) (string, error) {
hash, err := hashstructure.Hash(policy, nil)
if err != nil {
return "", fmt.Errorf("while calculating hash from policy: %w", err)
return "", fmt.Errorf("NAISERATOR-4331: while calculating hash from policy: %w", err)
}
basename := fmt.Sprintf("%s-%s-%x", appName, strings.ToLower(policy.Resource.Kind), hash)
return namegen.ShortName(basename, validation.DNS1035LabelMaxLength)
Expand Down Expand Up @@ -88,7 +88,7 @@ func CreatePolicyMember(source Source, ast *resource.Ast, cfg Config) error {
for _, p := range gcp.Permissions {
policyMember, err := policyMember(source, p, cfg.GetGoogleProjectID(), cfg.GetGoogleTeamProjectID())
if err != nil {
return fmt.Errorf("unable to create iampolicymember: %w", err)
return fmt.Errorf("NAISERATOR-2113: unable to create iampolicymember: %w", err)
}
ast.AppendOperation(resource.OperationCreateIfNotExists, policyMember)
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/resourcecreator/google/sql/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func CreateInstance(source Source, ast *resource.Ast, cfg Config) error {
}

if len(manifestGCP.SqlInstances) > 1 {
return fmt.Errorf("only one sql instance is supported even though the spec indicates otherwise")
return fmt.Errorf("NAISERATOR-8231: only one sql instance is supported even though the spec indicates otherwise")
}

naisSqlInstance, err := NaisCloudSqlInstanceWithDefaults(manifestGCP.Instance(), sourceName)
Expand All @@ -69,7 +69,7 @@ func CreateInstance(source Source, ast *resource.Ast, cfg Config) error {
}

if len(naisSqlInstance.Databases) > 1 {
return fmt.Errorf("only one sql database is supported even though the spec indicates otherwise")
return fmt.Errorf("NAISERATOR-5338: only one sql database is supported even though the spec indicates otherwise")
}

naisSqlDatabase := naisSqlInstance.Database()
Expand Down Expand Up @@ -119,7 +119,7 @@ func CreateGoogleSqlInstance(objectMeta metav1.ObjectMeta, instance *nais_io_v1.
util.SetAnnotation(&objectMeta, google.StateIntoSpec, google.StateIntoSpecValue)

if len(instance.Tier) == 0 {
return nil, fmt.Errorf("DB instance tier missing. Previous default value was `db-f1-micro` (recommended only for development); closest recommended value for production use is `db-custom-1-3840`")
return nil, fmt.Errorf("NAISERATOR-5213: DB instance tier missing. Previous default value was `db-f1-micro` (recommended only for development); closest recommended value for production use is `db-custom-1-3840`")
}

if !instance.CascadingDelete {
Expand Down Expand Up @@ -211,7 +211,7 @@ func CreateGoogleSqlInstance(objectMeta metav1.ObjectMeta, instance *nais_io_v1.

func NaisCloudSqlInstanceWithDefaults(instance *nais_io_v1.CloudSqlInstance, appName string) (*nais_io_v1.CloudSqlInstance, error) {
if instance == nil {
return nil, fmt.Errorf("sql instance not defined")
return nil, fmt.Errorf("NAISERATOR-1856: sql instance not defined")
}

defaultInstance := nais_io_v1.CloudSqlInstance{
Expand All @@ -224,7 +224,7 @@ func NaisCloudSqlInstanceWithDefaults(instance *nais_io_v1.CloudSqlInstance, app

err := mergo.Merge(instance, defaultInstance)
if err != nil {
return nil, fmt.Errorf("unable to merge default sqlinstance values: %s", err)
return nil, fmt.Errorf("NAISERATOR-6817: unable to merge default sqlinstance values: %s", err)
}

// Have to do this check explicitly as mergo is not able to distinguish between nil pointer and 0.
Expand Down
16 changes: 8 additions & 8 deletions pkg/resourcecreator/google/sql/instance_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const eightk = 8192
func ValidateFlag(key string, value string) error {
validatorFunc := validators[key]
if validatorFunc == nil {
return fmt.Errorf("couldn't find validator for instance flag '%s'", key)
return fmt.Errorf("NAISERATOR-9097: couldn't find validator for instance flag '%s'", key)
}
return validatorFunc(value)
}
Expand Down Expand Up @@ -215,7 +215,7 @@ func intWithinRange(min int, max int) func(n string) error {
return err
}
if i < min || i > max {
return fmt.Errorf("%d is not between %d and %d", i, min, max)
return fmt.Errorf("NAISERATOR-6177: %d is not between %d and %d", i, min, max)
}
return nil
}
Expand All @@ -228,7 +228,7 @@ func floatWithinRange(min float64, max float64) func(n string) error {
return err
}
if f < min || f > max {
return fmt.Errorf("%f is not between %f and %f", f, min, max)
return fmt.Errorf("NAISERATOR-9076: %f is not between %f and %f", f, min, max)
}
return nil
}
Expand All @@ -239,7 +239,7 @@ func inEnum(allowedVals []string) func(val string) error {
parts := strings.Split(commaSeparatedSuppliedVals, ",")
for _, v := range parts {
if !slices.Contains(allowedVals, v) {
return fmt.Errorf("%s is not in %v", commaSeparatedSuppliedVals, allowedVals)
return fmt.Errorf("NAISERATOR-1428: %s is not in %v", commaSeparatedSuppliedVals, allowedVals)
}
}
return nil
Expand All @@ -253,7 +253,7 @@ func unit(unitSize int) func(n string) error {
return err
}
if i%unitSize != 0 {
return fmt.Errorf("%d is not a unit of %d", i, unitSize)
return fmt.Errorf("NAISERATOR-5189: %d is not a unit of %d", i, unitSize)
}
return nil
}
Expand All @@ -270,21 +270,21 @@ func toBool(str string) error {
if str == "on" || str == "off" {
return nil
}
return fmt.Errorf("expected 'on|off' int, got '%s'", str)
return fmt.Errorf("NAISERATOR-6766: expected 'on|off' int, got '%s'", str)
}

func toInt(str string) (int, error) {
i, err := strconv.Atoi(str)
if err != nil {
return 0, fmt.Errorf("expected an int, got '%s'", str)
return 0, fmt.Errorf("NAISERATOR-7760: expected an int, got '%s'", str)
}
return i, nil
}

func toFloat(str string) (float64, error) {
f, err := strconv.ParseFloat(str, 64)
if err != nil {
return 0, fmt.Errorf("expected a float, got '%s'", str)
return 0, fmt.Errorf("NAISERATOR-0265: expected a float, got '%s'", str)
}
return f, nil
}
Loading