@@ -44,17 +44,32 @@ func Init() (err error) {
4444}
4545
4646func initRepos () error {
47+ var newRepos = map [string ]* stackRepo {}
48+
4749 for repoName , repoConfig := range config .RepoConfigs {
50+ if repo , exists := repos [repoName ]; exists {
51+ newRepos [repoName ] = repo
52+ delete (repos , repoName )
53+ continue
54+ }
55+
4856 repoPath := path .Join (config .ReposPath , repoName )
4957 auth , err := createHTTPBasicAuth (repoName )
5058 if err != nil {
5159 return err
5260 }
53- repos [repoName ], err = newStackRepo (repoName , repoPath , repoConfig .Url , auth )
61+ newRepos [repoName ], err = newStackRepo (repoName , repoPath , repoConfig .Url , auth )
5462 if err != nil {
5563 return err
5664 }
5765 }
66+
67+ if len (repos ) != 0 {
68+ logger .Info ("Some repos were removed from the stack: %v" , repos )
69+ }
70+
71+ repos = newRepos
72+
5873 return nil
5974}
6075
@@ -92,17 +107,38 @@ func createHTTPBasicAuth(repoName string) (*http.BasicAuth, error) {
92107}
93108
94109func initStacks () error {
110+ var newStacks = map [string ]* swarmStack {}
111+ var newStackStatus = map [string ]* StackStatus {}
112+
95113 for stack , stackConfig := range config .StackConfigs {
96114 stackRepo , ok := repos [stackConfig .Repo ]
97115 if ! ok {
98116 return fmt .Errorf ("error initializing %s stack, no such repo: %s" , stack , stackConfig .Repo )
99117 }
118+
100119 discoverSecrets := config .SopsSecretsDiscovery || stackConfig .SopsSecretsDiscovery
101120 swarmStack := newSwarmStack (stack , stackRepo , stackConfig .Branch , stackConfig .ComposeFile , stackConfig .SopsFiles , stackConfig .ValuesFile , discoverSecrets )
102- stacks = append (stacks , swarmStack )
103- stackStatus [stack ] = & StackStatus {}
104- stackStatus [stack ].RepoURL = stackRepo .url
121+
122+ newStacks [stack ] = swarmStack
123+ if _ , exists := stacks [stack ]; exists {
124+ delete (stacks , stack )
125+ }
126+
127+ newStackStatus [stack ] = & StackStatus {}
128+ newStackStatus [stack ].RepoURL = stackRepo .url
129+ if _ , exists := stackStatus [stack ]; exists {
130+ delete (stacks , stack )
131+ }
105132 }
133+
134+ if len (stacks ) != 0 {
135+ logger .Info ("Some stacks were removed: %v" , stacks )
136+ // Todo: do we need to do something for this.
137+ }
138+
139+ stacks = newStacks
140+ stackStatus = newStackStatus
141+
106142 return nil
107143}
108144
0 commit comments