Skip to content

Commit

Permalink
Loosen the validation around unused field
Browse files Browse the repository at this point in the history
When fields in RSync spec is not used, some are allowed to be present,
such as `spec.git`, `spec.oci`, `spec.helm`, and
`spec.xxx.gcpServiceAccountEmail`. However, `spec.xxx.secretRef` is not
allowed when it is not used. The reconciler-manager already checks if it
is the proper auth type before copying to the config-management-system
Namespace, so it is okay to loosen the validation for this field.

This commit also refactors the auth types to reduce code duplication.
  • Loading branch information
nan-yu committed Feb 3, 2024
1 parent 1d50f52 commit c0a746a
Show file tree
Hide file tree
Showing 43 changed files with 985 additions and 601 deletions.
4 changes: 2 additions & 2 deletions cmd/helm-sync/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ var (
flIncludeCRDs = flag.String("include-crds", os.Getenv(reconcilermanager.HelmIncludeCRDs),
"include CRDs in the helm rendering output")
flAuth = flag.String("auth", util.EnvString(reconcilermanager.HelmAuthType, string(configsync.AuthNone)),
fmt.Sprintf("the authentication type for access to the Helm repository. Must be one of %s, %s, %s, %s or %s. Defaults to %s",
configsync.AuthGCPServiceAccount, configsync.AuthK8sServiceAccount, configsync.AuthToken, configsync.AuthGCENode, configsync.AuthNone, configsync.AuthNone))
fmt.Sprintf("the authentication type for access to the Helm repository. Must be one of %s. Defaults to %s",
configsync.SupportedAuthTypes(configsync.HelmSource), configsync.AuthNone))
flReleaseName = flag.String("release-name", os.Getenv(reconcilermanager.HelmReleaseName),
"the name of helm release")
flNamespace = flag.String("namespace", os.Getenv(reconcilermanager.HelmReleaseNamespace),
Expand Down
3 changes: 1 addition & 2 deletions cmd/hydration-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"k8s.io/klog/v2"
"k8s.io/klog/v2/klogr"
"kpt.dev/configsync/pkg/api/configsync"
"kpt.dev/configsync/pkg/api/configsync/v1beta1"
"kpt.dev/configsync/pkg/hydrate"
"kpt.dev/configsync/pkg/importer/filesystem/cmpath"
"kpt.dev/configsync/pkg/kmetrics"
Expand Down Expand Up @@ -111,7 +110,7 @@ func main() {

hydrator := &hydrate.Hydrator{
DonePath: absDonePath,
SourceType: v1beta1.SourceType(*sourceType),
SourceType: configsync.SourceType(*sourceType),
SourceRoot: absSourceRootDir,
HydratedRoot: absHydratedRootDir,
SourceLink: *sourceLinkDir,
Expand Down
15 changes: 8 additions & 7 deletions cmd/nomos/status/cluster_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"kpt.dev/configsync/cmd/nomos/util"
v1 "kpt.dev/configsync/pkg/api/configmanagement/v1"
"kpt.dev/configsync/pkg/api/configsync"
"kpt.dev/configsync/pkg/api/configsync/v1beta1"
"kpt.dev/configsync/pkg/reposync"
"kpt.dev/configsync/pkg/rootsync"
Expand Down Expand Up @@ -75,7 +76,7 @@ func unavailableCluster(ref string) *ClusterState {
type RepoState struct {
scope string
syncName string
sourceType v1beta1.SourceType
sourceType configsync.SourceType
git *v1beta1.Git
oci *v1beta1.Oci
helm *v1beta1.HelmBase
Expand Down Expand Up @@ -133,13 +134,13 @@ func (r *RepoState) printRows(writer io.Writer) {
}
}

func sourceString(sourceType v1beta1.SourceType, git *v1beta1.Git, oci *v1beta1.Oci, helm *v1beta1.HelmBase) string {
func sourceString(sourceType configsync.SourceType, git *v1beta1.Git, oci *v1beta1.Oci, helm *v1beta1.HelmBase) string {
switch sourceType {
case v1beta1.OciSource:
case configsync.OciSource:
return ociString(oci)
case v1beta1.HelmSource:
case configsync.HelmSource:
return helmString(helm)
case v1beta1.GitSource:
case configsync.GitSource:
return gitString(git)
}
return gitString(git)
Expand Down Expand Up @@ -307,7 +308,7 @@ func namespaceRepoStatus(rs *v1beta1.RepoSync, rg *unstructured.Unstructured, sy
repostate := &RepoState{
scope: rs.Namespace,
syncName: rs.Name,
sourceType: v1beta1.SourceType(rs.Spec.SourceType),
sourceType: configsync.SourceType(rs.Spec.SourceType),
git: rs.Spec.Git,
oci: rs.Spec.Oci,
helm: reposync.GetHelmBase(rs.Spec.Helm),
Expand Down Expand Up @@ -409,7 +410,7 @@ func RootRepoStatus(rs *v1beta1.RootSync, rg *unstructured.Unstructured, syncing
repostate := &RepoState{
scope: "<root>",
syncName: rs.Name,
sourceType: v1beta1.SourceType(rs.Spec.SourceType),
sourceType: configsync.SourceType(rs.Spec.SourceType),
git: rs.Spec.Git,
oci: rs.Spec.Oci,
helm: rootsync.GetHelmBase(rs.Spec.Helm),
Expand Down
Loading

0 comments on commit c0a746a

Please sign in to comment.