Skip to content

Commit 8b3f192

Browse files
smiratalos-bot
authored andcommitted
feat: update naming conventions for resources and types
Rename 'core' resources to 'meta' (including namespace), introduce new naming concept: * internal type name should be `CamelCases.some.cosi.dev` * resource definition id is `camelecases.some.cosi.dev` * displayed type name is `CamelCase` * type aliases are `camelcase`, `camelcases`, `cc`, `ccs` Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
1 parent 28dd9aa commit 8b3f192

16 files changed

Lines changed: 325 additions & 134 deletions

File tree

.golangci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
22
#
3-
# Generated on 2020-12-30T20:27:21Z by kres latest.
3+
# Generated on 2021-03-01T18:00:23Z by kres latest.
44

55

66
# options for analysis running
@@ -128,6 +128,7 @@ linters:
128128
- wrapcheck
129129
- paralleltest
130130
- exhaustivestruct
131+
- forbidigo
131132
disable-all: false
132133
fast: false
133134

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
44
#
5-
# Generated on 2020-12-30T20:27:21Z by kres latest.
5+
# Generated on 2021-03-01T18:00:23Z by kres latest.
66

77
ARG TOOLCHAIN
88

@@ -24,7 +24,7 @@ FROM toolchain AS tools
2424
ENV GO111MODULE on
2525
ENV CGO_ENABLED 0
2626
ENV GOPATH /go
27-
RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b /bin v1.33.0
27+
RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b /bin v1.36.0
2828
ARG GOFUMPT_VERSION
2929
RUN cd $(mktemp -d) \
3030
&& go mod init tmp \

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.14
55
require (
66
github.com/AlekSi/pointer v1.1.0
77
github.com/cenkalti/backoff/v4 v4.1.0
8+
github.com/gertd/go-pluralize v0.1.7
89
github.com/hashicorp/go-memdb v1.3.0
910
github.com/stretchr/testify v1.6.1
1011
github.com/talos-systems/go-retry v0.2.0

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ github.com/cenkalti/backoff/v4 v4.1.0 h1:c8LkOFQTzuO0WBM/ae5HdGQuZPfPxp7lqBRwQRm
44
github.com/cenkalti/backoff/v4 v4.1.0/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw=
55
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
66
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
7+
github.com/gertd/go-pluralize v0.1.7 h1:RgvJTJ5W7olOoAks97BOwOlekBFsLEyh00W48Z6ZEZY=
8+
github.com/gertd/go-pluralize v0.1.7/go.mod h1:O4eNeeIf91MHh1GJ2I47DNtaesm66NYvjYgAahcqSDQ=
79
github.com/hashicorp/go-immutable-radix v1.3.0 h1:8exGP7ego3OmkfksihtSouGMZ+hQrhxx+FVELeXpVPE=
810
github.com/hashicorp/go-immutable-radix v1.3.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
911
github.com/hashicorp/go-memdb v1.3.0 h1:xdXq34gBOMEloa9rlGStLxmfX/dyIK8htOv36dQUwHU=
@@ -18,6 +20,8 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
1820
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
1921
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
2022
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
23+
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
24+
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
2125
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
2226
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
2327
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=

pkg/controller/runtime/adapter.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ func (adapter *adapter) UpdateDependencies(deps []controller.Dependency) error {
6767
break
6868
}
6969

70-
add := false
71-
delete := false
70+
shouldAdd := false
71+
shouldDelete := false
7272

7373
switch {
7474
case i >= len(deps):
75-
delete = true
75+
shouldDelete = true
7676
case j >= len(dbDeps):
77-
add = true
77+
shouldAdd = true
7878
default:
7979
dI := deps[i]
8080
dJ := dbDeps[j]
@@ -84,15 +84,15 @@ func (adapter *adapter) UpdateDependencies(deps []controller.Dependency) error {
8484
i++
8585
j++
8686
case dependency.EqualKeys(&dI, &dJ):
87-
add, delete = true, true
87+
shouldAdd, shouldDelete = true, true
8888
case dependency.Less(&dI, &dJ):
89-
add = true
89+
shouldAdd = true
9090
default:
91-
delete = true
91+
shouldDelete = true
9292
}
9393
}
9494

95-
if add {
95+
if shouldAdd {
9696
if err := adapter.runtime.depDB.AddControllerDependency(adapter.name, deps[i]); err != nil {
9797
return fmt.Errorf("error adding controller dependency: %w", err)
9898
}
@@ -104,7 +104,7 @@ func (adapter *adapter) UpdateDependencies(deps []controller.Dependency) error {
104104
i++
105105
}
106106

107-
if delete {
107+
if shouldDelete {
108108
if err := adapter.runtime.depDB.DeleteControllerDependency(adapter.name, dbDeps[j]); err != nil {
109109
return fmt.Errorf("error deleting controller dependency: %w", err)
110110
}

pkg/resource/core/resource_definition.go

Lines changed: 0 additions & 76 deletions
This file was deleted.
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
// License, v. 2.0. If a copy of the MPL was not distributed with this
33
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
44

5-
// Package core provides definition of core system resources.
6-
package core
5+
// Package meta provides definition of core metadata resources.
6+
package meta
77

88
import "github.com/talos-systems/os-runtime/pkg/resource"
99

10-
// NamespaceName is the name of 'core' namespace.
11-
const NamespaceName resource.Namespace = "core"
10+
// NamespaceName is the name of 'meta' namespace.
11+
const NamespaceName resource.Namespace = "meta"
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// License, v. 2.0. If a copy of the MPL was not distributed with this
33
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
44

5-
package core
5+
package meta
66

77
import (
88
"fmt"
@@ -11,7 +11,7 @@ import (
1111
)
1212

1313
// NamespaceType is the type of Namespace.
14-
const NamespaceType = resource.Type("core/namespace")
14+
const NamespaceType = resource.Type("Namespaces.meta.cosi.dev")
1515

1616
// Namespace provides metadata about namespaces.
1717
type Namespace struct {
@@ -21,9 +21,7 @@ type Namespace struct {
2121

2222
// NamespaceSpec provides Namespace definition.
2323
type NamespaceSpec struct {
24-
Description string `yaml:"description"`
25-
System bool `yaml:"system"`
26-
UserWritable bool `yaml:"userWritable"`
24+
Description string `yaml:"description"`
2725
}
2826

2927
// NewNamespace initializes a Namespace resource.
@@ -64,7 +62,7 @@ func (r *Namespace) DeepCopy() resource.Resource {
6462
func (r *Namespace) ResourceDefinition() ResourceDefinitionSpec {
6563
return ResourceDefinitionSpec{
6664
Type: NamespaceType,
67-
Aliases: []resource.Type{"namespace", "namespaces", "ns"},
6865
DefaultNamespace: NamespaceName,
66+
Aliases: []resource.Type{"ns"},
6967
}
7068
}

0 commit comments

Comments
 (0)